소스 검색

case study working

Claudio Gomes 6 년 전
부모
커밋
b9694b029e
1개의 변경된 파일31개의 추가작업 그리고 15개의 파일을 삭제
  1. 31 15
      HintCO/src/ua/ansymo/hintco/CandidateSpaceGenerator.xtend

+ 31 - 15
HintCO/src/ua/ansymo/hintco/CandidateSpaceGenerator.xtend

@@ -58,9 +58,9 @@ class CandidateSpaceGenerator {
 	def handleSoftwareHints(ContractSet hints, Candidates cs) {
 		/*
 		 * Assumes that there is only one software controller fmu.
-		 * Creates a new candidate scenario, duplicate of the previous one, with higher weight.
 		 * Then sets the scenario step size to the frequency of the software controller.
 		 * Then sets every other fmu to a higher rate, giving preference to interpolations over extrapolations.
+		 * The ports that are fed by the outputs of the software controller have zero order extrapolations/interpolations
 		 */
 	 	if (!(hints.eAllContents.filter(FMUProperty).filter[p | p.property === FMUPropertyEnum.EXEC_RATE].size == 1)){
 	 		return 
@@ -93,6 +93,13 @@ class CandidateSpaceGenerator {
 		val ctrlUnitName = (prop.^var as FMUProperty).fmu.signal.stripQuotes
 		val ctrlUnit = scenario.cosimunits.findFirst[u | u.identifier == ctrlUnitName]
 		Assert.isNotNull(ctrlUnit, "Contracts refers to a non existing unit: " + ctrlUnitName)
+		
+		for (outP : ctrlUnit.ports.filter(OutputPortInstance)){
+			for(inP : outP.valueTo){
+				createDefaultInPortApproximations(inP, 0)
+			}
+		}
+		
 		val otherUnits = scenario.cosimunits.filter[u | u.identifier != ctrlUnitName]
 		for (otherUnit : otherUnits) {
 			createDefaultInPortsApproximations(otherUnit, #[10])
@@ -160,20 +167,7 @@ class CandidateSpaceGenerator {
 		{
 			val inPorts = unit.ports.filter(InputPortInstance)
 			for (inPort : inPorts) {
-				val xor = f.createXorAdaptation()
-				inPort.adaptation = xor
-				{
-					val extra = f.createExtrapolationAdaptation()
-					xor.children.add(extra)
-					extra.weight = 0
-					extra.order = 1
-				}
-				{
-					val intra = f.createInterpolationAdaptation()
-					xor.children.add(intra)
-					intra.weight = 10
-					intra.order = 1
-				}
+				createDefaultInPortApproximations(inPort, 1)
 			}
 		}
 		
@@ -197,4 +191,26 @@ class CandidateSpaceGenerator {
 		}
 	}
 	
+	
+	def createDefaultInPortApproximations(InputPortInstance inPort, int order) {
+		if (inPort.adaptation !== null){
+			return
+		}
+		val f = HintcoFactory.eINSTANCE
+		val xor = f.createXorAdaptation()
+		inPort.adaptation = xor
+		{
+			val extra = f.createExtrapolationAdaptation()
+			xor.children.add(extra)
+			extra.weight = 0
+			extra.order = order
+		}
+		{
+			val intra = f.createInterpolationAdaptation()
+			xor.children.add(intra)
+			intra.weight = 10
+			intra.order = order
+		}
+	}
+	
 }