|
@@ 1987-2395 (lines=409) @@
|
| 1984 |
|
* @throws DomainComponentNotFoundException |
| 1985 |
|
* @throws SynchronizationCycleException |
| 1986 |
|
*/ |
| 1987 |
|
private void doCreateSynchronizationFromSingletonDecision(DDLSynchronization ddlSynch, DomainComponent comp, PlanDataBase pdb) |
| 1988 |
|
throws DomainComponentNotFoundException, SynchronizationCycleException |
| 1989 |
|
{ |
| 1990 |
|
// setup auxiliary data structures |
| 1991 |
|
Map<String, TokenVariable> label2variable = new HashMap<>(); |
| 1992 |
|
Map<String, TokenVariable> decId2variable = new HashMap<>(); |
| 1993 |
|
|
| 1994 |
|
// get reference decision |
| 1995 |
|
DDLSingletonStateVariableComponentDecision ddlDec = (DDLSingletonStateVariableComponentDecision) ddlSynch.getReference(); |
| 1996 |
|
|
| 1997 |
|
// get trigger value |
| 1998 |
|
ComponentValue valTrigger = comp.getValueByName(ddlDec.getName()); |
| 1999 |
|
|
| 2000 |
|
// create synchronization |
| 2001 |
|
SynchronizationRule rule = pdb.createSynchronizationRule(valTrigger, |
| 2002 |
|
ddlDec.getParameterNames().toArray(new String[ddlDec.getParameterNames().size()])); |
| 2003 |
|
// add entry to parameter label index |
| 2004 |
|
for (String label : rule.getTriggerer().getParameterLabels()) { |
| 2005 |
|
label2variable.put(label, rule.getTriggerer()); |
| 2006 |
|
} |
| 2007 |
|
|
| 2008 |
|
// check target values |
| 2009 |
|
for (DDLInstantiatedComponentDecision ddlTarget : ddlSynch.getTargets().values()) |
| 2010 |
|
{ |
| 2011 |
|
// get target component |
| 2012 |
|
DomainComponent targetComponent = pdb.getComponentByName(ddlTarget.getComponent()); |
| 2013 |
|
// check target component type |
| 2014 |
|
switch (targetComponent.getType()) |
| 2015 |
|
{ |
| 2016 |
|
// state variable component |
| 2017 |
|
case SV_EXTERNAL : |
| 2018 |
|
case SV_FUNCTIONAL : |
| 2019 |
|
case SV_PRIMITIVE : |
| 2020 |
|
{ |
| 2021 |
|
// check target decision |
| 2022 |
|
DDLComponentDecision ddlTargetDecision = ddlTarget.getComponentDecision(); |
| 2023 |
|
// check decision type |
| 2024 |
|
switch (ddlTargetDecision.getDecisionType()) |
| 2025 |
|
{ |
| 2026 |
|
// decision with parameters |
| 2027 |
|
case SINGLETON : |
| 2028 |
|
{ |
| 2029 |
|
// cast decision |
| 2030 |
|
DDLSingletonStateVariableComponentDecision ddlSingletonTarget = (DDLSingletonStateVariableComponentDecision) ddlTargetDecision; |
| 2031 |
|
|
| 2032 |
|
// get target value |
| 2033 |
|
ComponentValue targetValue = targetComponent.getValueByName(ddlSingletonTarget.getName()); |
| 2034 |
|
|
| 2035 |
|
// add token variable |
| 2036 |
|
TokenVariable target = rule.addTokenVariable(targetValue, |
| 2037 |
|
ddlSingletonTarget.getParameterNames().toArray(new String[ddlSingletonTarget.getParameterNames().size()])); |
| 2038 |
|
|
| 2039 |
|
// check solving knowledge |
| 2040 |
|
if (!ddlTarget.getParameters().isEmpty()) { |
| 2041 |
|
// check mandatory expansion |
| 2042 |
|
if (ddlTarget.getParameters().contains("!")) { |
| 2043 |
|
// set knowledge |
| 2044 |
|
target.setMandatoryExpansion(); |
| 2045 |
|
} |
| 2046 |
|
|
| 2047 |
|
// check mandatory unification |
| 2048 |
|
if (ddlTarget.getParameters().contains("?")) { |
| 2049 |
|
target.setMandatoryUnification(); |
| 2050 |
|
} |
| 2051 |
|
} |
| 2052 |
|
|
| 2053 |
|
// add entry to index |
| 2054 |
|
for (String label : target.getParameterLabels()) { |
| 2055 |
|
// add entry |
| 2056 |
|
label2variable.put(label, target); |
| 2057 |
|
} |
| 2058 |
|
|
| 2059 |
|
// get synchronization decision's ID |
| 2060 |
|
String id = ddlTarget.getId(); |
| 2061 |
|
// check if target id already exists |
| 2062 |
|
if (decId2variable.containsKey(id)) { |
| 2063 |
|
throw new RuntimeException("Duplicated decision ID <" + id + "> on synchronization " + rule); |
| 2064 |
|
} |
| 2065 |
|
|
| 2066 |
|
// add entry |
| 2067 |
|
decId2variable.put(id, target); |
| 2068 |
|
} |
| 2069 |
|
break; |
| 2070 |
|
|
| 2071 |
|
// ground decision |
| 2072 |
|
case GROUND : |
| 2073 |
|
{ |
| 2074 |
|
// cast decision |
| 2075 |
|
DDLSimpleGroundStateVariableComponentDecision ddlGroundTarget = (DDLSimpleGroundStateVariableComponentDecision) ddlTargetDecision; |
| 2076 |
|
// get target value |
| 2077 |
|
ComponentValue targetValue = targetComponent.getValueByName(ddlGroundTarget.getName()); |
| 2078 |
|
|
| 2079 |
|
// add token variable with no parameter labels |
| 2080 |
|
TokenVariable target = rule.addTokenVariable(targetValue, new String[] {}); |
| 2081 |
|
|
| 2082 |
|
// check solving knowledge |
| 2083 |
|
if (!ddlTarget.getParameters().isEmpty()) { |
| 2084 |
|
// check mandatory expansion |
| 2085 |
|
if (ddlTarget.getParameters().contains("!")) { |
| 2086 |
|
// set knowledge |
| 2087 |
|
target.setMandatoryExpansion(); |
| 2088 |
|
} |
| 2089 |
|
|
| 2090 |
|
// check mandatory unification |
| 2091 |
|
if (ddlTarget.getParameters().contains("?")) { |
| 2092 |
|
target.setMandatoryUnification(); |
| 2093 |
|
} |
| 2094 |
|
} |
| 2095 |
|
|
| 2096 |
|
// get synchronization decision's ID |
| 2097 |
|
String id = ddlTarget.getId(); |
| 2098 |
|
// check if target id already exists |
| 2099 |
|
if (decId2variable.containsKey(id)) { |
| 2100 |
|
throw new RuntimeException("Duplicated decision ID <" + id + "> on synchronization " + rule); |
| 2101 |
|
} |
| 2102 |
|
|
| 2103 |
|
// add entry |
| 2104 |
|
decId2variable.put(id, target); |
| 2105 |
|
} |
| 2106 |
|
break; |
| 2107 |
|
|
| 2108 |
|
default : { |
| 2109 |
|
throw new RuntimeException("Unknown state variable decision type - " + ddlTargetDecision.getDecisionType()); |
| 2110 |
|
} |
| 2111 |
|
} |
| 2112 |
|
|
| 2113 |
|
|
| 2114 |
|
} |
| 2115 |
|
break; |
| 2116 |
|
|
| 2117 |
|
// discrete resource component |
| 2118 |
|
case RESOURCE_DISCRETE : |
| 2119 |
|
{ |
| 2120 |
|
// check target decision |
| 2121 |
|
DDLComponentDecision ddlTargetDecision = ddlTarget.getComponentDecision(); |
| 2122 |
|
// cast decision |
| 2123 |
|
DDLRenewableResourceComponentDecision ddlRequirementTarget = (DDLRenewableResourceComponentDecision) ddlTargetDecision; |
| 2124 |
|
// get target component |
| 2125 |
|
DiscreteResource resource = (DiscreteResource) targetComponent; |
| 2126 |
|
|
| 2127 |
|
// get target value |
| 2128 |
|
ComponentValue targetValue = resource.getRequirementValue(); |
| 2129 |
|
// add token variable |
| 2130 |
|
TokenVariable target = rule.addTokenVariable(targetValue, |
| 2131 |
|
new String[] {ddlRequirementTarget.getRequirementName()}); |
| 2132 |
|
|
| 2133 |
|
// add entry to index |
| 2134 |
|
for (String label : target.getParameterLabels()) { |
| 2135 |
|
// add entry |
| 2136 |
|
label2variable.put(label, target); |
| 2137 |
|
} |
| 2138 |
|
|
| 2139 |
|
// get synchronization decision's ID |
| 2140 |
|
String id = ddlTarget.getId(); |
| 2141 |
|
// check if target id already exists |
| 2142 |
|
if (decId2variable.containsKey(id)) { |
| 2143 |
|
throw new RuntimeException("Duplicated decision ID <" + id + "> on synchronization " + rule); |
| 2144 |
|
} |
| 2145 |
|
|
| 2146 |
|
// add entry |
| 2147 |
|
decId2variable.put(id, target); |
| 2148 |
|
} |
| 2149 |
|
break; |
| 2150 |
|
|
| 2151 |
|
// reservoir resource component |
| 2152 |
|
case RESOURCE_RESERVOIR : |
| 2153 |
|
{ |
| 2154 |
|
// get target component |
| 2155 |
|
ReservoirResource resource = (ReservoirResource) targetComponent; |
| 2156 |
|
|
| 2157 |
|
// check target decision |
| 2158 |
|
DDLComponentDecision ddlTargetDecision = ddlTarget.getComponentDecision(); |
| 2159 |
|
// cast decision |
| 2160 |
|
DDLConsumableResourceComponentDecision ddlConsumableTarget = (DDLConsumableResourceComponentDecision) ddlTargetDecision; |
| 2161 |
|
// check decision type |
| 2162 |
|
switch (ddlConsumableTarget.getComponentDecisionType()) |
| 2163 |
|
{ |
| 2164 |
|
// resource consumption |
| 2165 |
|
case Consumption : |
| 2166 |
|
{ |
| 2167 |
|
// get target value |
| 2168 |
|
ComponentValue consumption = resource.getConsumptionValue(); |
| 2169 |
|
// add token variable |
| 2170 |
|
TokenVariable target = rule.addTokenVariable(consumption, |
| 2171 |
|
new String[] {ddlConsumableTarget.getParameterName()}); |
| 2172 |
|
|
| 2173 |
|
// add entry to index |
| 2174 |
|
for (String label : target.getParameterLabels()) { |
| 2175 |
|
// add entry |
| 2176 |
|
label2variable.put(label, target); |
| 2177 |
|
} |
| 2178 |
|
|
| 2179 |
|
// get synchronization decision's ID |
| 2180 |
|
String id = ddlTarget.getId(); |
| 2181 |
|
// check if target id already exists |
| 2182 |
|
if (decId2variable.containsKey(id)) { |
| 2183 |
|
throw new RuntimeException("Duplicated decision ID <" + id + "> on synchronization " + rule); |
| 2184 |
|
} |
| 2185 |
|
|
| 2186 |
|
// add entry |
| 2187 |
|
decId2variable.put(id, target); |
| 2188 |
|
} |
| 2189 |
|
break; |
| 2190 |
|
|
| 2191 |
|
// resource production |
| 2192 |
|
case Production : |
| 2193 |
|
{ |
| 2194 |
|
// get target value |
| 2195 |
|
ComponentValue production = resource.getProductionValue(); |
| 2196 |
|
// add token variable |
| 2197 |
|
TokenVariable target = rule.addTokenVariable(production, |
| 2198 |
|
new String[] {ddlConsumableTarget.getParameterName()}); |
| 2199 |
|
|
| 2200 |
|
// add entry to index |
| 2201 |
|
for (String label : target.getParameterLabels()) { |
| 2202 |
|
// add entry |
| 2203 |
|
label2variable.put(label, target); |
| 2204 |
|
} |
| 2205 |
|
|
| 2206 |
|
// get synchronization decision's ID |
| 2207 |
|
String id = ddlTarget.getId(); |
| 2208 |
|
// check if target id already exists |
| 2209 |
|
if (decId2variable.containsKey(id)) { |
| 2210 |
|
throw new RuntimeException("Duplicated decision ID <" + id + "> on synchronization " + rule); |
| 2211 |
|
} |
| 2212 |
|
|
| 2213 |
|
// add entry |
| 2214 |
|
decId2variable.put(id, target); |
| 2215 |
|
} |
| 2216 |
|
break; |
| 2217 |
|
} |
| 2218 |
|
|
| 2219 |
|
|
| 2220 |
|
} |
| 2221 |
|
break; |
| 2222 |
|
|
| 2223 |
|
default : { |
| 2224 |
|
// unknown target component type |
| 2225 |
|
throw new RuntimeException("Unknownw target component found into synchronization constraint" + ddlTarget); |
| 2226 |
|
} |
| 2227 |
|
} |
| 2228 |
|
} |
| 2229 |
|
|
| 2230 |
|
// set temporal relations |
| 2231 |
|
for (DDLTemporalRelation ddlRel : ddlSynch.getTemporalRelations()) |
| 2232 |
|
{ |
| 2233 |
|
// check relation type |
| 2234 |
|
DDLTemporalRelationType ddlRelType = ddlRel.getRelationType(); |
| 2235 |
|
|
| 2236 |
|
// get constraint reference |
| 2237 |
|
TokenVariable cref; |
| 2238 |
|
// check reference's ID |
| 2239 |
|
if (ddlRel.getFrom() == null) { |
| 2240 |
|
cref = rule.getTriggerer(); |
| 2241 |
|
} |
| 2242 |
|
else { |
| 2243 |
|
// check if reference exists |
| 2244 |
|
if (!decId2variable.containsKey(ddlRel.getFrom())) { |
| 2245 |
|
throw new RuntimeException("Unknown decision ID found <" + ddlRel.getFrom() + "> on synchronization " + rule); |
| 2246 |
|
} |
| 2247 |
|
|
| 2248 |
|
// get reference decision |
| 2249 |
|
cref = decId2variable.get(ddlRel.getFrom()); |
| 2250 |
|
} |
| 2251 |
|
|
| 2252 |
|
// check if target exists |
| 2253 |
|
if (!decId2variable.containsKey(ddlRel.getTo())) { |
| 2254 |
|
throw new RuntimeException("Unknown decision ID found <" + ddlRel.getTo() + "> on synchronization " + rule); |
| 2255 |
|
} |
| 2256 |
|
|
| 2257 |
|
// get constraint target |
| 2258 |
|
TokenVariable ctarget = decId2variable.get(ddlRel.getTo()); |
| 2259 |
|
|
| 2260 |
|
// create constraint |
| 2261 |
|
this.addConstraintToSynchronization(rule, cref, ctarget, ddlRelType); |
| 2262 |
|
} |
| 2263 |
|
|
| 2264 |
|
// set parameter relations |
| 2265 |
|
List<DDLParameterConstraint> ddlParameterConstraints = ddlSynch.getParameterConstraints(); |
| 2266 |
|
for (DDLParameterConstraint ddlpc : ddlParameterConstraints) |
| 2267 |
|
{ |
| 2268 |
|
// check constraint type |
| 2269 |
|
switch (ddlpc.getConstraintType()) |
| 2270 |
|
{ |
| 2271 |
|
// enumeration parameter constraint |
| 2272 |
|
case ENUMERATION : |
| 2273 |
|
{ |
| 2274 |
|
// get enumeration constraint |
| 2275 |
|
DDLEnumerationParameterConstraint ddlEnumerationConstraint = (DDLEnumerationParameterConstraint) ddlpc; |
| 2276 |
|
// get reference variable |
| 2277 |
|
String leftTerm = ddlEnumerationConstraint.getLeftTerm(); |
| 2278 |
|
|
| 2279 |
|
// check if parameter exists |
| 2280 |
|
if (!label2variable.containsKey(leftTerm)) { |
| 2281 |
|
throw new RuntimeException("Unknown reference parameter found <" + leftTerm + "> on synchronization " + rule); |
| 2282 |
|
} |
| 2283 |
|
|
| 2284 |
|
// get reference |
| 2285 |
|
TokenVariable pcReference = label2variable.get(leftTerm); |
| 2286 |
|
|
| 2287 |
|
// get value |
| 2288 |
|
String value = ddlEnumerationConstraint.getValue(); |
| 2289 |
|
// get relation type |
| 2290 |
|
RelationType relType; |
| 2291 |
|
switch (ddlEnumerationConstraint.getEnumerationConstraintType()) { |
| 2292 |
|
// equal constraint |
| 2293 |
|
case EQ : { |
| 2294 |
|
// set relation type |
| 2295 |
|
relType = RelationType.BIND_PARAMETER; |
| 2296 |
|
} |
| 2297 |
|
break; |
| 2298 |
|
|
| 2299 |
|
default : { |
| 2300 |
|
|
| 2301 |
|
throw new RuntimeException("Unknownw enumeration constraint type " + ddlEnumerationConstraint.getEnumerationConstraintType()); |
| 2302 |
|
} |
| 2303 |
|
} |
| 2304 |
|
|
| 2305 |
|
// create binding constraint |
| 2306 |
|
rule.addBindingConstraint(pcReference, relType, leftTerm, value); |
| 2307 |
|
} |
| 2308 |
|
break; |
| 2309 |
|
|
| 2310 |
|
// binary parameter constraint |
| 2311 |
|
case NUMERIC : |
| 2312 |
|
{ |
| 2313 |
|
// get numeric constraint |
| 2314 |
|
DDLNumericParameterConstraint ddlNumericConstraint = (DDLNumericParameterConstraint) ddlpc; |
| 2315 |
|
// get reference variable |
| 2316 |
|
String leftTerm = ddlNumericConstraint.getLeftTerm(); |
| 2317 |
|
|
| 2318 |
|
// check if parameter exists |
| 2319 |
|
if (!label2variable.containsKey(leftTerm)) { |
| 2320 |
|
throw new RuntimeException("Unknown reference parameter found <" + leftTerm + "> on synchronization " + rule); |
| 2321 |
|
} |
| 2322 |
|
|
| 2323 |
|
// get reference |
| 2324 |
|
TokenVariable pcReference = label2variable.get(leftTerm); |
| 2325 |
|
|
| 2326 |
|
// check if binary |
| 2327 |
|
if (ddlNumericConstraint.isBinary()) |
| 2328 |
|
{ |
| 2329 |
|
// get relation type |
| 2330 |
|
RelationType relType; |
| 2331 |
|
switch (ddlNumericConstraint.getNumericConstraintType()) { |
| 2332 |
|
// equal constraint |
| 2333 |
|
case EQ : { |
| 2334 |
|
// set relation type |
| 2335 |
|
relType = RelationType.EQUAL_PARAMETER; |
| 2336 |
|
} |
| 2337 |
|
break; |
| 2338 |
|
|
| 2339 |
|
// not equal constraint |
| 2340 |
|
case NEQ : { |
| 2341 |
|
// set relation type |
| 2342 |
|
relType = RelationType.NOT_EQUAL_PARAMETER; |
| 2343 |
|
} |
| 2344 |
|
break; |
| 2345 |
|
|
| 2346 |
|
default : { |
| 2347 |
|
|
| 2348 |
|
throw new RuntimeException("Unknownw numeric constraint type " + ddlNumericConstraint.getNumericConstraintType()); |
| 2349 |
|
} |
| 2350 |
|
} |
| 2351 |
|
|
| 2352 |
|
// check targets |
| 2353 |
|
for (String rightTerm : ddlNumericConstraint.getRightVariables()) { |
| 2354 |
|
// check if parameter exists |
| 2355 |
|
if (!label2variable.containsKey(rightTerm)) { |
| 2356 |
|
throw new RuntimeException("Unknown target found <" + rightTerm + "> on synchronization " + rule); |
| 2357 |
|
} |
| 2358 |
|
|
| 2359 |
|
// get target variable |
| 2360 |
|
TokenVariable pcTarget = label2variable.get(rightTerm); |
| 2361 |
|
|
| 2362 |
|
// create constraint |
| 2363 |
|
rule.addParameterConstraint(pcReference, pcTarget, relType, leftTerm, rightTerm); |
| 2364 |
|
} |
| 2365 |
|
} |
| 2366 |
|
else { |
| 2367 |
|
// not binary constraint, set bind constraint |
| 2368 |
|
int value = ddlNumericConstraint.getRightCoefficients().get(0); |
| 2369 |
|
// get relation type |
| 2370 |
|
RelationType relType; |
| 2371 |
|
switch (ddlNumericConstraint.getNumericConstraintType()) |
| 2372 |
|
{ |
| 2373 |
|
// equal constraint |
| 2374 |
|
case EQ : |
| 2375 |
|
{ |
| 2376 |
|
// set relation type |
| 2377 |
|
relType = RelationType.BIND_PARAMETER; |
| 2378 |
|
} |
| 2379 |
|
break; |
| 2380 |
|
|
| 2381 |
|
default : { |
| 2382 |
|
|
| 2383 |
|
throw new RuntimeException("Unknownw numeric constraint type " + ddlNumericConstraint.getNumericConstraintType()); |
| 2384 |
|
} |
| 2385 |
|
} |
| 2386 |
|
|
| 2387 |
|
// create constraint |
| 2388 |
|
rule.addBindingConstraint(pcReference, relType, leftTerm, Integer.toString(value)); |
| 2389 |
|
} |
| 2390 |
|
} |
| 2391 |
|
} |
| 2392 |
|
} |
| 2393 |
|
|
| 2394 |
|
// add synchronization rule |
| 2395 |
|
pdb.addSynchronizationRule(rule); |
| 2396 |
|
} |
| 2397 |
|
|
| 2398 |
|
/** |
|
@@ 772-1179 (lines=408) @@
|
| 769 |
|
* @throws DomainComponentNotFoundException |
| 770 |
|
* @throws SynchronizationCycleException |
| 771 |
|
*/ |
| 772 |
|
private void doCreateSynchronizationFromRenewableResourceValue(DDLSynchronization ddlSynch, DiscreteResource comp, PlanDataBase pdb) |
| 773 |
|
throws DomainComponentNotFoundException, SynchronizationCycleException |
| 774 |
|
{ |
| 775 |
|
// setup auxiliary data structures |
| 776 |
|
Map<String, TokenVariable> label2variable = new HashMap<>(); |
| 777 |
|
Map<String, TokenVariable> decId2variable = new HashMap<>(); |
| 778 |
|
|
| 779 |
|
// get reference decision |
| 780 |
|
DDLRenewableResourceComponentDecision ddlDec = (DDLRenewableResourceComponentDecision) ddlSynch.getReference(); |
| 781 |
|
|
| 782 |
|
// get trigger value |
| 783 |
|
RequirementResourceValue valTrigger = comp.getRequirementValue(); |
| 784 |
|
|
| 785 |
|
// create synchronization |
| 786 |
|
SynchronizationRule rule = pdb.createSynchronizationRule(valTrigger, new String[] {ddlDec.getRequirementName()}); |
| 787 |
|
// add entry to parameter label index |
| 788 |
|
for (String label : rule.getTriggerer().getParameterLabels()) { |
| 789 |
|
label2variable.put(label, rule.getTriggerer()); |
| 790 |
|
} |
| 791 |
|
|
| 792 |
|
// check target values |
| 793 |
|
for (DDLInstantiatedComponentDecision ddlTarget : ddlSynch.getTargets().values()) |
| 794 |
|
{ |
| 795 |
|
// get target component |
| 796 |
|
DomainComponent targetComponent = pdb.getComponentByName(ddlTarget.getComponent()); |
| 797 |
|
// check target component type |
| 798 |
|
switch (targetComponent.getType()) |
| 799 |
|
{ |
| 800 |
|
// state variable component |
| 801 |
|
case SV_EXTERNAL : |
| 802 |
|
case SV_FUNCTIONAL : |
| 803 |
|
case SV_PRIMITIVE : |
| 804 |
|
{ |
| 805 |
|
// check target decision |
| 806 |
|
DDLComponentDecision ddlTargetDecision = ddlTarget.getComponentDecision(); |
| 807 |
|
// check decision type |
| 808 |
|
switch (ddlTargetDecision.getDecisionType()) |
| 809 |
|
{ |
| 810 |
|
// decision with parameters |
| 811 |
|
case SINGLETON : |
| 812 |
|
{ |
| 813 |
|
// cast decision |
| 814 |
|
DDLSingletonStateVariableComponentDecision ddlSingletonTarget = (DDLSingletonStateVariableComponentDecision) ddlTargetDecision; |
| 815 |
|
|
| 816 |
|
// get target value |
| 817 |
|
ComponentValue targetValue = targetComponent.getValueByName(ddlSingletonTarget.getName()); |
| 818 |
|
|
| 819 |
|
// add token variable |
| 820 |
|
TokenVariable target = rule.addTokenVariable(targetValue, |
| 821 |
|
ddlSingletonTarget.getParameterNames().toArray(new String[ddlSingletonTarget.getParameterNames().size()])); |
| 822 |
|
|
| 823 |
|
// check solving knowledge |
| 824 |
|
if (!ddlTarget.getParameters().isEmpty()) { |
| 825 |
|
// check mandatory expansion |
| 826 |
|
if (ddlTarget.getParameters().contains("!")) { |
| 827 |
|
// set knowledge |
| 828 |
|
target.setMandatoryExpansion(); |
| 829 |
|
} |
| 830 |
|
|
| 831 |
|
// check mandatory unification |
| 832 |
|
if (ddlTarget.getParameters().contains("?")) { |
| 833 |
|
target.setMandatoryUnification(); |
| 834 |
|
} |
| 835 |
|
} |
| 836 |
|
|
| 837 |
|
// add entry to index |
| 838 |
|
for (String label : target.getParameterLabels()) { |
| 839 |
|
// add entry |
| 840 |
|
label2variable.put(label, target); |
| 841 |
|
} |
| 842 |
|
|
| 843 |
|
// get synchronization decision's ID |
| 844 |
|
String id = ddlTarget.getId(); |
| 845 |
|
// check if target id already exists |
| 846 |
|
if (decId2variable.containsKey(id)) { |
| 847 |
|
throw new RuntimeException("Duplicated decision ID <" + id + "> on synchronization " + rule); |
| 848 |
|
} |
| 849 |
|
|
| 850 |
|
// add entry |
| 851 |
|
decId2variable.put(id, target); |
| 852 |
|
} |
| 853 |
|
break; |
| 854 |
|
|
| 855 |
|
// ground decision |
| 856 |
|
case GROUND : |
| 857 |
|
{ |
| 858 |
|
// cast decision |
| 859 |
|
DDLSimpleGroundStateVariableComponentDecision ddlGroundTarget = (DDLSimpleGroundStateVariableComponentDecision) ddlTargetDecision; |
| 860 |
|
// get target value |
| 861 |
|
ComponentValue targetValue = targetComponent.getValueByName(ddlGroundTarget.getName()); |
| 862 |
|
|
| 863 |
|
// add token variable with no parameter labels |
| 864 |
|
TokenVariable target = rule.addTokenVariable(targetValue, new String[] {}); |
| 865 |
|
|
| 866 |
|
// check solving knowledge |
| 867 |
|
if (!ddlTarget.getParameters().isEmpty()) { |
| 868 |
|
// check mandatory expansion |
| 869 |
|
if (ddlTarget.getParameters().contains("!")) { |
| 870 |
|
// set knowledge |
| 871 |
|
target.setMandatoryExpansion(); |
| 872 |
|
} |
| 873 |
|
|
| 874 |
|
// check mandatory unification |
| 875 |
|
if (ddlTarget.getParameters().contains("?")) { |
| 876 |
|
target.setMandatoryUnification(); |
| 877 |
|
} |
| 878 |
|
} |
| 879 |
|
|
| 880 |
|
// get synchronization decision's ID |
| 881 |
|
String id = ddlTarget.getId(); |
| 882 |
|
// check if target id already exists |
| 883 |
|
if (decId2variable.containsKey(id)) { |
| 884 |
|
throw new RuntimeException("Duplicated decision ID <" + id + "> on synchronization " + rule); |
| 885 |
|
} |
| 886 |
|
|
| 887 |
|
// add entry |
| 888 |
|
decId2variable.put(id, target); |
| 889 |
|
} |
| 890 |
|
break; |
| 891 |
|
|
| 892 |
|
default : { |
| 893 |
|
throw new RuntimeException("Unknown state variable decision type - " + ddlTargetDecision.getDecisionType()); |
| 894 |
|
} |
| 895 |
|
} |
| 896 |
|
|
| 897 |
|
|
| 898 |
|
} |
| 899 |
|
break; |
| 900 |
|
|
| 901 |
|
// discrete resource component |
| 902 |
|
case RESOURCE_DISCRETE : |
| 903 |
|
{ |
| 904 |
|
// check target decision |
| 905 |
|
DDLComponentDecision ddlTargetDecision = ddlTarget.getComponentDecision(); |
| 906 |
|
// cast decision |
| 907 |
|
DDLRenewableResourceComponentDecision ddlRequirementTarget = (DDLRenewableResourceComponentDecision) ddlTargetDecision; |
| 908 |
|
// get target component |
| 909 |
|
DiscreteResource resource = (DiscreteResource) targetComponent; |
| 910 |
|
|
| 911 |
|
// get target value |
| 912 |
|
ComponentValue targetValue = resource.getRequirementValue(); |
| 913 |
|
// add token variable |
| 914 |
|
TokenVariable target = rule.addTokenVariable(targetValue, |
| 915 |
|
new String[] {ddlRequirementTarget.getRequirementName()}); |
| 916 |
|
|
| 917 |
|
// add entry to index |
| 918 |
|
for (String label : target.getParameterLabels()) { |
| 919 |
|
// add entry |
| 920 |
|
label2variable.put(label, target); |
| 921 |
|
} |
| 922 |
|
|
| 923 |
|
// get synchronization decision's ID |
| 924 |
|
String id = ddlTarget.getId(); |
| 925 |
|
// check if target id already exists |
| 926 |
|
if (decId2variable.containsKey(id)) { |
| 927 |
|
throw new RuntimeException("Duplicated decision ID <" + id + "> on synchronization " + rule); |
| 928 |
|
} |
| 929 |
|
|
| 930 |
|
// add entry |
| 931 |
|
decId2variable.put(id, target); |
| 932 |
|
} |
| 933 |
|
break; |
| 934 |
|
|
| 935 |
|
// reservoir resource component |
| 936 |
|
case RESOURCE_RESERVOIR : |
| 937 |
|
{ |
| 938 |
|
// get target component |
| 939 |
|
ReservoirResource resource = (ReservoirResource) targetComponent; |
| 940 |
|
|
| 941 |
|
// check target decision |
| 942 |
|
DDLComponentDecision ddlTargetDecision = ddlTarget.getComponentDecision(); |
| 943 |
|
// cast decision |
| 944 |
|
DDLConsumableResourceComponentDecision ddlConsumableTarget = (DDLConsumableResourceComponentDecision) ddlTargetDecision; |
| 945 |
|
// check decision type |
| 946 |
|
switch (ddlConsumableTarget.getComponentDecisionType()) |
| 947 |
|
{ |
| 948 |
|
// resource consumption |
| 949 |
|
case Consumption : |
| 950 |
|
{ |
| 951 |
|
// get target value |
| 952 |
|
ComponentValue consumption = resource.getConsumptionValue(); |
| 953 |
|
// add token variable |
| 954 |
|
TokenVariable target = rule.addTokenVariable(consumption, |
| 955 |
|
new String[] {ddlConsumableTarget.getParameterName()}); |
| 956 |
|
|
| 957 |
|
// add entry to index |
| 958 |
|
for (String label : target.getParameterLabels()) { |
| 959 |
|
// add entry |
| 960 |
|
label2variable.put(label, target); |
| 961 |
|
} |
| 962 |
|
|
| 963 |
|
// get synchronization decision's ID |
| 964 |
|
String id = ddlTarget.getId(); |
| 965 |
|
// check if target id already exists |
| 966 |
|
if (decId2variable.containsKey(id)) { |
| 967 |
|
throw new RuntimeException("Duplicated decision ID <" + id + "> on synchronization " + rule); |
| 968 |
|
} |
| 969 |
|
|
| 970 |
|
// add entry |
| 971 |
|
decId2variable.put(id, target); |
| 972 |
|
} |
| 973 |
|
break; |
| 974 |
|
|
| 975 |
|
// resource production |
| 976 |
|
case Production : |
| 977 |
|
{ |
| 978 |
|
// get target value |
| 979 |
|
ComponentValue production = resource.getProductionValue(); |
| 980 |
|
// add token variable |
| 981 |
|
TokenVariable target = rule.addTokenVariable(production, |
| 982 |
|
new String[] {ddlConsumableTarget.getParameterName()}); |
| 983 |
|
|
| 984 |
|
// add entry to index |
| 985 |
|
for (String label : target.getParameterLabels()) { |
| 986 |
|
// add entry |
| 987 |
|
label2variable.put(label, target); |
| 988 |
|
} |
| 989 |
|
|
| 990 |
|
// get synchronization decision's ID |
| 991 |
|
String id = ddlTarget.getId(); |
| 992 |
|
// check if target id already exists |
| 993 |
|
if (decId2variable.containsKey(id)) { |
| 994 |
|
throw new RuntimeException("Duplicated decision ID <" + id + "> on synchronization " + rule); |
| 995 |
|
} |
| 996 |
|
|
| 997 |
|
// add entry |
| 998 |
|
decId2variable.put(id, target); |
| 999 |
|
} |
| 1000 |
|
break; |
| 1001 |
|
} |
| 1002 |
|
|
| 1003 |
|
|
| 1004 |
|
} |
| 1005 |
|
break; |
| 1006 |
|
|
| 1007 |
|
default : { |
| 1008 |
|
// unknown target component type |
| 1009 |
|
throw new RuntimeException("Unknownw target component found into synchronization constraint" + ddlTarget); |
| 1010 |
|
} |
| 1011 |
|
} |
| 1012 |
|
} |
| 1013 |
|
|
| 1014 |
|
// set temporal relations |
| 1015 |
|
for (DDLTemporalRelation ddlRel : ddlSynch.getTemporalRelations()) |
| 1016 |
|
{ |
| 1017 |
|
// check relation type |
| 1018 |
|
DDLTemporalRelationType ddlRelType = ddlRel.getRelationType(); |
| 1019 |
|
|
| 1020 |
|
// get constraint reference |
| 1021 |
|
TokenVariable cref; |
| 1022 |
|
// check reference's ID |
| 1023 |
|
if (ddlRel.getFrom() == null) { |
| 1024 |
|
cref = rule.getTriggerer(); |
| 1025 |
|
} |
| 1026 |
|
else { |
| 1027 |
|
// check if reference exists |
| 1028 |
|
if (!decId2variable.containsKey(ddlRel.getFrom())) { |
| 1029 |
|
throw new RuntimeException("Unknown decision ID found <" + ddlRel.getFrom() + "> on synchronization " + rule); |
| 1030 |
|
} |
| 1031 |
|
|
| 1032 |
|
// get reference decision |
| 1033 |
|
cref = decId2variable.get(ddlRel.getFrom()); |
| 1034 |
|
} |
| 1035 |
|
|
| 1036 |
|
// check if target exists |
| 1037 |
|
if (!decId2variable.containsKey(ddlRel.getTo())) { |
| 1038 |
|
throw new RuntimeException("Unknown decision ID found <" + ddlRel.getTo() + "> on synchronization " + rule); |
| 1039 |
|
} |
| 1040 |
|
|
| 1041 |
|
// get constraint target |
| 1042 |
|
TokenVariable ctarget = decId2variable.get(ddlRel.getTo()); |
| 1043 |
|
|
| 1044 |
|
// create constraint |
| 1045 |
|
this.addConstraintToSynchronization(rule, cref, ctarget, ddlRelType); |
| 1046 |
|
} |
| 1047 |
|
|
| 1048 |
|
// set parameter relations |
| 1049 |
|
List<DDLParameterConstraint> ddlParameterConstraints = ddlSynch.getParameterConstraints(); |
| 1050 |
|
for (DDLParameterConstraint ddlpc : ddlParameterConstraints) |
| 1051 |
|
{ |
| 1052 |
|
// check constraint type |
| 1053 |
|
switch (ddlpc.getConstraintType()) |
| 1054 |
|
{ |
| 1055 |
|
// enumeration parameter constraint |
| 1056 |
|
case ENUMERATION : |
| 1057 |
|
{ |
| 1058 |
|
// get enumeration constraint |
| 1059 |
|
DDLEnumerationParameterConstraint ddlEnumerationConstraint = (DDLEnumerationParameterConstraint) ddlpc; |
| 1060 |
|
// get reference variable |
| 1061 |
|
String leftTerm = ddlEnumerationConstraint.getLeftTerm(); |
| 1062 |
|
|
| 1063 |
|
// check if parameter exists |
| 1064 |
|
if (!label2variable.containsKey(leftTerm)) { |
| 1065 |
|
throw new RuntimeException("Unknown reference parameter found <" + leftTerm + "> on synchronization " + rule); |
| 1066 |
|
} |
| 1067 |
|
|
| 1068 |
|
// get reference |
| 1069 |
|
TokenVariable pcReference = label2variable.get(leftTerm); |
| 1070 |
|
|
| 1071 |
|
// get value |
| 1072 |
|
String value = ddlEnumerationConstraint.getValue(); |
| 1073 |
|
// get relation type |
| 1074 |
|
RelationType relType; |
| 1075 |
|
switch (ddlEnumerationConstraint.getEnumerationConstraintType()) { |
| 1076 |
|
// equal constraint |
| 1077 |
|
case EQ : { |
| 1078 |
|
// set relation type |
| 1079 |
|
relType = RelationType.BIND_PARAMETER; |
| 1080 |
|
} |
| 1081 |
|
break; |
| 1082 |
|
|
| 1083 |
|
default : { |
| 1084 |
|
|
| 1085 |
|
throw new RuntimeException("Unknownw enumeration constraint type " + ddlEnumerationConstraint.getEnumerationConstraintType()); |
| 1086 |
|
} |
| 1087 |
|
} |
| 1088 |
|
|
| 1089 |
|
// create binding constraint |
| 1090 |
|
rule.addBindingConstraint(pcReference, relType, leftTerm, value); |
| 1091 |
|
} |
| 1092 |
|
break; |
| 1093 |
|
|
| 1094 |
|
// binary parameter constraint |
| 1095 |
|
case NUMERIC : |
| 1096 |
|
{ |
| 1097 |
|
// get numeric constraint |
| 1098 |
|
DDLNumericParameterConstraint ddlNumericConstraint = (DDLNumericParameterConstraint) ddlpc; |
| 1099 |
|
// get reference variable |
| 1100 |
|
String leftTerm = ddlNumericConstraint.getLeftTerm(); |
| 1101 |
|
|
| 1102 |
|
// check if parameter exists |
| 1103 |
|
if (!label2variable.containsKey(leftTerm)) { |
| 1104 |
|
throw new RuntimeException("Unknown reference parameter found <" + leftTerm + "> on synchronization " + rule); |
| 1105 |
|
} |
| 1106 |
|
|
| 1107 |
|
// get reference |
| 1108 |
|
TokenVariable pcReference = label2variable.get(leftTerm); |
| 1109 |
|
|
| 1110 |
|
// check if binary |
| 1111 |
|
if (ddlNumericConstraint.isBinary()) |
| 1112 |
|
{ |
| 1113 |
|
// get relation type |
| 1114 |
|
RelationType relType; |
| 1115 |
|
switch (ddlNumericConstraint.getNumericConstraintType()) { |
| 1116 |
|
// equal constraint |
| 1117 |
|
case EQ : { |
| 1118 |
|
// set relation type |
| 1119 |
|
relType = RelationType.EQUAL_PARAMETER; |
| 1120 |
|
} |
| 1121 |
|
break; |
| 1122 |
|
|
| 1123 |
|
// not equal constraint |
| 1124 |
|
case NEQ : { |
| 1125 |
|
// set relation type |
| 1126 |
|
relType = RelationType.NOT_EQUAL_PARAMETER; |
| 1127 |
|
} |
| 1128 |
|
break; |
| 1129 |
|
|
| 1130 |
|
default : { |
| 1131 |
|
|
| 1132 |
|
throw new RuntimeException("Unknownw numeric constraint type " + ddlNumericConstraint.getNumericConstraintType()); |
| 1133 |
|
} |
| 1134 |
|
} |
| 1135 |
|
|
| 1136 |
|
// check targets |
| 1137 |
|
for (String rightTerm : ddlNumericConstraint.getRightVariables()) { |
| 1138 |
|
// check if parameter exists |
| 1139 |
|
if (!label2variable.containsKey(rightTerm)) { |
| 1140 |
|
throw new RuntimeException("Unknown target found <" + rightTerm + "> on synchronization " + rule); |
| 1141 |
|
} |
| 1142 |
|
|
| 1143 |
|
// get target variable |
| 1144 |
|
TokenVariable pcTarget = label2variable.get(rightTerm); |
| 1145 |
|
|
| 1146 |
|
// create constraint |
| 1147 |
|
rule.addParameterConstraint(pcReference, pcTarget, relType, leftTerm, rightTerm); |
| 1148 |
|
} |
| 1149 |
|
} |
| 1150 |
|
else { |
| 1151 |
|
// not binary constraint, set bind constraint |
| 1152 |
|
int value = ddlNumericConstraint.getRightCoefficients().get(0); |
| 1153 |
|
// get relation type |
| 1154 |
|
RelationType relType; |
| 1155 |
|
switch (ddlNumericConstraint.getNumericConstraintType()) |
| 1156 |
|
{ |
| 1157 |
|
// equal constraint |
| 1158 |
|
case EQ : |
| 1159 |
|
{ |
| 1160 |
|
// set relation type |
| 1161 |
|
relType = RelationType.BIND_PARAMETER; |
| 1162 |
|
} |
| 1163 |
|
break; |
| 1164 |
|
|
| 1165 |
|
default : { |
| 1166 |
|
|
| 1167 |
|
throw new RuntimeException("Unknownw numeric constraint type " + ddlNumericConstraint.getNumericConstraintType()); |
| 1168 |
|
} |
| 1169 |
|
} |
| 1170 |
|
|
| 1171 |
|
// create constraint |
| 1172 |
|
rule.addBindingConstraint(pcReference, relType, leftTerm, Integer.toString(value)); |
| 1173 |
|
} |
| 1174 |
|
} |
| 1175 |
|
} |
| 1176 |
|
} |
| 1177 |
|
|
| 1178 |
|
// add synchronization rule |
| 1179 |
|
pdb.addSynchronizationRule(rule); |
| 1180 |
|
} |
| 1181 |
|
|
| 1182 |
|
/** |