Explorar o código

sketch of algorithm

Claudio Gomes %!s(int64=5) %!d(string=hai) anos
pai
achega
e605776654

+ 17 - 0
HintCOEngine/src/ua/ansymo/hintco/AlgebraicLoopVariantProcessor.xtend

@@ -1,6 +1,7 @@
 package ua.ansymo.hintco
 
 import java.util.Deque
+import org.eclipse.core.runtime.Assert
 
 class AlgebraicLoopVariantProcessor implements IVariantProcessor {
 	
@@ -10,7 +11,23 @@ class AlgebraicLoopVariantProcessor implements IVariantProcessor {
 		runner = r
 	}
 	
+	/*
+	 * This method will perform roughly the following steps:
+	 * 1. Transform the scenario (assumed to be non-hierarchical) into a graph where each node represents a cosim unit, and each connection between cosim units represents the cost of executing the latter after executing the former.
+	 * 2. Find the best way to break the algebraic loops, that is, find the optimal trigger sequence.
+	 * 3. Define the operation schedule from the optimal trigger sequence. As this breaks the loop, it means that some semantic adaptations have to be overridden. 
+	 * Since the last step is tricky when higher order approximations and power bond adaptations are used, these are not supported for now. 
+	 */
 	override process(Deque<VariantDiagram> ns, String variantID, ConstraintsStack constraints, HintConfiguration cs) {
+		val scenario = ModelQuery.findRootScenario(ns)
+		
+		if (!scenario.eAllContents.filter(Scenario).empty) { 
+			throw new UnsupportedOperationException("Algebraic loop optimization is not implemented for hierarchical co-simulation scenarios.")
+		}
+		scenario.eAllContents.filter(InterpolationAdaptation).forEach[adapt | Assert.isTrue(adapt.order == 0, "Only constant interpolations supported in algebraic loop optimizer. Adaptation " + adapt + " is not a constant interpolation.")]
+		Assert.isTrue(scenario.eAllContents.filter(PowerBondAdaptation).empty, "Powerbond adaptations cannot be used with algebraic loop optimizer, as the optimal trigger sequence may override these.")
+		
+		
 	}
 	
 }

+ 1 - 2
HintCOEngine/src/ua/ansymo/hintco/CandidatesGenerator.xtend

@@ -351,8 +351,7 @@ class CandidatesGenerator {
 					if (! scenarioNodeSrc.precedes.contains(scenarioNodeTrg) &&
 						ModelQuery.pathExists(scenarioNodeSrc, scenarioNodeTrg, constraints, cs)) {
 						Assert.isTrue(
-							addConstraint(scenarioNodeSrc, scenarioNodeTrg, constraints, n, cs) ==
-								AddConstraintResult.SUCCESS)
+							addConstraint(scenarioNodeSrc, scenarioNodeTrg, constraints, n, cs) == AddConstraintResult.SUCCESS)
 					}
 				}
 			}