Skip to content

Commit

Permalink
adjust manual attachment & transformation, fix replace options (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
LaviniaStiliadou authored Apr 26, 2024
1 parent cadaf0b commit a016807
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,19 @@ export default class PatternReplaceMenuProvider {
});

if (element.host.type === quantmeConsts.QUANTUM_CIRCUIT_LOADING_TASK) {
filteredOptionsBasedOnAttachers =
quantmeReplaceOptions.AUGMENTATION_PATTERN.filter((option) => {
filteredOptionsBasedOnAttachers = filteredOptionsBasedOnAttachers.filter(
(option) => {
return option.target.type === consts.BIASED_INITIAL_STATE;
});
}
);
}

if (element.host.type === quantmeConsts.QUANTUM_CIRCUIT_EXECUTION_TASK) {
filteredOptionsBasedOnAttachers =
quantmeReplaceOptions.AUGMENTATION_PATTERN.filter((option) => {
filteredOptionsBasedOnAttachers = filteredOptionsBasedOnAttachers.filter(
(option) => {
return option.target.type !== consts.BIASED_INITIAL_STATE;
});
}
);
}

// error correction is not allowed with error mitigation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ export default class PatternRules extends RuleProvider {
}
}

if (
attachedElementTypesWithPolicy === 1 &&
target.type === quantmeConsts.QUANTUM_CIRCUIT_LOADING_TASK
) {
return false;
}

if (target.type === quantmeConsts.QUANTUM_CIRCUIT_EXECUTION_TASK) {
// we cannot attach behavioral pattern to any task
attachedElementTypesWithPolicy += consts.BEHAVIORAL_PATTERNS.length;

// we cannot attach the biased initial state
attachedElementTypesWithPolicy += 1;
}

for (let i = 0; i < target.attachers.length; i++) {
if (specificPolicies.includes(target.attachers[i].type)) {
specificPolicies = specificPolicies.filter(
Expand Down Expand Up @@ -139,8 +154,7 @@ export default class PatternRules extends RuleProvider {
}
if (
shapeToAttach.type.includes("pattern") &&
(target.type === "bpmn:ServiceTask" ||
target.type === "bpmn:SubProcess")
target.type === "bpmn:SubProcess"
) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,40 +479,44 @@ export function attachPatternsToSuitableTasks(

// contains all flowElements of the parent and its children
let children = new Set();
patterns[j].attachedToRef.flowElements.forEach((flowElement) =>
children.add(flowElement.id)
);
let hostFlowElements = patterns[j].attachedToRef.flowElements;
if (hostFlowElements !== undefined) {
hostFlowElements.forEach((flowElement) => children.add(flowElement.id));

patterns[j].attachedToRef.flowElements.forEach((child) => {
if (
(child.$type && child.$type === "bpmn:SubProcess") ||
(child.type && child.type === "bpmn:SubProcess")
) {
// Recursively retrieve the subprocess's flowElements
let subProcessFlowElements = retrieveFlowElements(
child.flowElements,
elementRegistry
);
subProcessFlowElements.forEach((flowElement) =>
children.add(flowElement)
);
}
});
hostFlowElements.forEach((child) => {
if (
(child.$type && child.$type === "bpmn:SubProcess") ||
(child.type && child.type === "bpmn:SubProcess")
) {
// Recursively retrieve the subprocess's flowElements
let subProcessFlowElements = retrieveFlowElements(
child.flowElements,
elementRegistry
);
subProcessFlowElements.forEach((flowElement) =>
children.add(flowElement)
);
}
});

children.values().forEach((id) => {
attachPatternsToSuitableConstruct(
elementRegistry.get(id),
pattern.type,
modeling
);
});
children.values().forEach((id) => {
attachPatternsToSuitableConstruct(
elementRegistry.get(id),
pattern.type,
modeling
);
});
}
}
}

for (let i = 0; i < patterns.length; i++) {
// behavioral patterns are deleted after acting on the optimization candidate
if (!constants.BEHAVIORAL_PATTERNS.includes(patterns[i].task.$type)) {
modeling.removeShape(elementRegistry.get(patterns[i].task.id));
let hostFlowElements = patterns[i].attachedToRef.flowElements;
if (hostFlowElements !== undefined) {
// behavioral patterns are deleted after acting on the optimization candidate
if (!constants.BEHAVIORAL_PATTERNS.includes(patterns[i].task.$type)) {
modeling.removeShape(elementRegistry.get(patterns[i].task.id));
}
}
}
}

0 comments on commit a016807

Please sign in to comment.