Browse Source

added graph lib dependency and sample test

Claudio Gomes 4 years ago
parent
commit
4575066b76

+ 5 - 0
HintCOEngine/.classpath

@@ -20,5 +20,10 @@
 	<classpathentry kind="lib" path="lib/slf4j-simple.jar" sourcepath="lib/slf4j-simple-sources.jar"/>
 	<classpathentry kind="lib" path="lib/commons-compress-1.18.jar" sourcepath="lib/commons-compress-1.18-sources.jar"/>
 	<classpathentry kind="lib" path="lib/commons-io-2.6.jar" sourcepath="lib/commons-io-2.6-sources.jar"/>
+	<classpathentry kind="lib" path="lib/jgrapht-core-1.3.1.jar" sourcepath="lib/jgrapht-core-1.3.1-sources.jar">
+		<attributes>
+			<attribute name="javadoc_location" value="jar:platform:/resource/HintCOEngine/lib/jgrapht-core-1.3.1-javadoc.jar!/"/>
+		</attributes>
+	</classpathentry>
 	<classpathentry kind="output" path="output"/>
 </classpath>

+ 36 - 0
HintCOEngine/instances/algebraic_loop_opt_test.hintco

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="ASCII"?>
+<hintco:HintConfiguration xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:hintco="ua.ansymo.hintco">
+  <candidates identifier="Scenario" stopTime="10.0" stepSize="1.0" outputStepSize="1.0">
+    <cosimunits xsi:type="hintco:CosimUnitInstance" identifier="A" declaration="//@csuDeclarations.0">
+      <ports xsi:type="hintco:InputPortInstance" identifier="3fromB" valueFrom="//@candidates.0/@cosimunits.1/@ports.1">
+        <adaptation xsi:type="hintco:InterpolationAdaptation"/>
+      </ports>
+      <ports xsi:type="hintco:InputPortInstance" identifier="5fromC" valueFrom="//@candidates.0/@cosimunits.2/@ports.2">
+        <adaptation xsi:type="hintco:InterpolationAdaptation"/>
+      </ports>
+      <ports xsi:type="hintco:OutputPortInstance" identifier="4toB" valueTo="//@candidates.0/@cosimunits.1/@ports.0"/>
+      <ports xsi:type="hintco:OutputPortInstance" identifier="3toC" valueTo="//@candidates.0/@cosimunits.2/@ports.1"/>
+    </cosimunits>
+    <cosimunits xsi:type="hintco:CosimUnitInstance" identifier="B" declaration="//@csuDeclarations.0">
+      <ports xsi:type="hintco:InputPortInstance" identifier="4fromA" valueFrom="//@candidates.0/@cosimunits.0/@ports.2">
+        <adaptation xsi:type="hintco:InterpolationAdaptation"/>
+      </ports>
+      <ports xsi:type="hintco:OutputPortInstance" identifier="3toA" valueTo="//@candidates.0/@cosimunits.0/@ports.0"/>
+      <ports xsi:type="hintco:OutputPortInstance" identifier="3toC" valueTo="//@candidates.0/@cosimunits.2/@ports.0"/>
+      <ports xsi:type="hintco:InputPortInstance" identifier="10fromC" valueFrom="//@candidates.0/@cosimunits.2/@ports.3">
+        <adaptation xsi:type="hintco:ExtrapolationAdaptation"/>
+      </ports>
+    </cosimunits>
+    <cosimunits xsi:type="hintco:CosimUnitInstance" identifier="C" declaration="//@csuDeclarations.0">
+      <ports xsi:type="hintco:InputPortInstance" identifier="3fromB" valueFrom="//@candidates.0/@cosimunits.1/@ports.2">
+        <adaptation xsi:type="hintco:InterpolationAdaptation"/>
+      </ports>
+      <ports xsi:type="hintco:InputPortInstance" identifier="3fromA" valueFrom="//@candidates.0/@cosimunits.0/@ports.3">
+        <adaptation xsi:type="hintco:InterpolationAdaptation"/>
+      </ports>
+      <ports xsi:type="hintco:OutputPortInstance" identifier="5toA" valueTo="//@candidates.0/@cosimunits.0/@ports.1"/>
+      <ports xsi:type="hintco:OutputPortInstance" identifier="10toB" valueTo="//@candidates.0/@cosimunits.1/@ports.3"/>
+    </cosimunits>
+  </candidates>
+  <csuDeclarations identifier="Node" path="resources/Scenario.fmu" guid="{a174734c-d15f-4ef0-838d-06526230b19e}"/>
+</hintco:HintConfiguration>

BIN
HintCOEngine/lib/jgrapht-core-1.3.1-javadoc.jar


BIN
HintCOEngine/lib/jgrapht-core-1.3.1-sources.jar


BIN
HintCOEngine/lib/jgrapht-core-1.3.1.jar


+ 16 - 1
HintCOEngine/src/ua/ansymo/hintco/AlgebraicLoopVariantProcessor.xtend

@@ -2,6 +2,8 @@ package ua.ansymo.hintco
 
 import java.util.Deque
 import org.eclipse.core.runtime.Assert
+import org.jgrapht.graph.DefaultWeightedEdge
+import org.jgrapht.graph.Multigraph
 
 class AlgebraicLoopVariantProcessor implements IVariantProcessor {
 	
@@ -11,6 +13,20 @@ class AlgebraicLoopVariantProcessor implements IVariantProcessor {
 		runner = r
 	}
 	
+	/*
+	 * Transforms a scenario into a cosim unit graph. 
+	 * The scenario already has some ordering constraints, as cosim units and ports are both precedence nodes.
+	 * The precendence constraints are placed in a way that it is easy to know whether two cosim units A and B should precede each other: whenever there is a precedence path that goes between them, of the following form:
+	 *  A -> B.in -> B where B.in is one of the input ports of B. If this is the case, then an edge should be created A --w-> B where w is the cost of extrapolating B.in.
+	 * In every other case, there is no edge between A->B.
+	 * This way, we preserve the extrapolation adaptations that have been defined by other hints.
+	 */
+	def transformToCosimUnitGraph(Scenario scenario) {
+		val g = new Multigraph(DefaultWeightedEdge)
+		
+		return g
+	}
+	
 	/*
 	 * 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.
@@ -27,7 +43,6 @@ class AlgebraicLoopVariantProcessor implements IVariantProcessor {
 		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.")
 		
-		
 	}
 	
 }

+ 22 - 0
HintCOEngine/test/ua/ansymo/hintco/test/AlgebraicLoopVariantProcessorTest.xtend

@@ -0,0 +1,22 @@
+package ua.ansymo.hintco.test
+
+import org.junit.Test
+import ua.ansymo.hintco.AlgebraicLoopVariantProcessor
+import ua.ansymo.hintco.ModelStorage
+import ua.ansymo.hintco.Scenario
+
+import static org.junit.Assert.*
+
+class AlgebraicLoopVariantProcessorTest {
+	
+	@Test
+	def void transformToCosimUnitGraphTest(){
+		val loader = new ModelStorage()
+		
+		val src = loader.loadCandidates("instances/algebraic_loop_opt_test.hintco")
+		val scenario = src.eAllContents.filter(Scenario).head
+		
+		assertNotNull(new AlgebraicLoopVariantProcessor(null).transformToCosimUnitGraph(scenario))
+	}
+	
+}