Commit 906e647f authored by Johannes Mey's avatar Johannes Mey
Browse files

improve ilp model

parent f7fd709a
ILP ::= IlpObjective IlpConstraint* IlpBound* IlpVariable* <Info:IlpVarInfo> ;
ILP ::= IlpObjective IlpConstraint* IlpVariable* ;
TimedOutILP:ILP ::= <Reason:String> ;
// objective kind is either minimize or maximize
......@@ -6,9 +6,7 @@ IlpObjective ::= <Kind:IlpObjectiveKind> IlpLeftHandSide ;
IlpConstraint ::= <Name:String> IlpLeftHandSide <ClauseComparator:ClauseComparator> <RightHandSide:double> ;
IlpBound ::= <Ref:IlpVariable> <Type:IlpBoundType> ;
IlpVariable ::= <Name:String> <Request:Request> <Impl:Implementation> ;
abstract IlpVariable ::= <Name:String> <Request:Request> <Impl:Implementation> <Illegal:boolean>;
IlpAllResourcesVariable:IlpVariable ;
IlpMappingVariable:IlpVariable ::= <Resource:Resource> ;
......
......@@ -8,12 +8,6 @@ aspect ILP {
MAXIMIZE
}
public enum IlpBoundType {
BINARY,
ZERO,
GREATER_EQUAL_ZERO
}
public class IlpString {
StringBuilder buffer;
......@@ -48,12 +42,10 @@ aspect ILP {
public class IlpVarInfo {
public java.util.Map<String, IlpVariable> vars;
public java.util.Map<Resource, IlpConstraint> resourceConstraints;
public java.util.Set<IlpVariable> illegal;
public IlpVarInfo() {
vars = new java.util.TreeMap<>();
resourceConstraints = new java.util.HashMap<>();
illegal = new java.util.HashSet<>();
}
public IlpVariable getIlpVariable(Request request, Implementation impl, Resource resource) {
......@@ -66,22 +58,18 @@ aspect ILP {
resourceConstraints.put(resource, resourceConstraint);
}
if (result == null) {
result = new IlpMappingVariable(varName, request, impl, resource);
result = new IlpMappingVariable(varName, request, impl, false, resource);
vars.put(varName, result);
resourceConstraint.getIlpLeftHandSide().addIlpTerm(new IlpTerm(1, result));
}
return result;
}
public void setIllegal(Request request, Implementation impl, Resource resource) {
illegal.add(getIlpVariable(request, impl, resource));
}
public IlpVariable getIlpVariable(Request request, Implementation impl) {
String varName = request.getIlpName() + "#" + impl.getIlpName();
IlpVariable result = vars.get(varName);
if (result == null) {
result = new IlpAllResourcesVariable(varName, request, impl);
result = new IlpAllResourcesVariable(varName, request, impl, false);
vars.put(varName, result);
}
return result;
......
......@@ -43,7 +43,7 @@ aspect ILP {
*/
syn ILP Root.getILP() {
de.tudresden.inf.st.mquat.utils.StopWatch stopWatch = de.tudresden.inf.st.mquat.utils.StopWatch.start();
// StopWatch stopWatch = StopWatch.start();
long timeoutValue = (long) de.tudresden.inf.st.mquat.utils.StaticSettings.get(ILP_TIMEOUT_VALUE);
java.util.concurrent.TimeUnit timeoutUnit = (java.util.concurrent.TimeUnit) de.tudresden.inf.st.mquat.utils.StaticSettings.get(ILP_TIMEOUT_UNIT);
long timeoutNanos = timeoutUnit.toNanos(timeoutValue);
......@@ -81,7 +81,6 @@ aspect ILP {
olhs.addIlpTerm(term);
oneImplLhs.addIlpTerm(new IlpTerm(1, var));
}
// 2.3 NFP-Negotiation: Requirements to other components
for (Clause reqClause : impl.requirementClauses()) {
if (stopWatch.time() > timeoutNanos) {
return ilpTimeout("Timeout in NFP-Negotiation");
......@@ -102,6 +101,7 @@ aspect ILP {
reqLhs.addIlpTerm(new IlpTerm(makeNegative(reqClause.evalUsing(request, resource)),
info.getIlpVariable(request, impl, resource)));
}
// 2b. non-functional requirements of required components
result.addIlpConstraint(new IlpConstraint(
request.getIlpName() + "_" + impl.getIlpName() + "_reqs_" +
designator.asSoftwareDesignator().getPropertyRef().getRef().getIlpName() + "_from_" +
......@@ -111,40 +111,39 @@ aspect ILP {
for (Resource resource : this.getHardwareModel().getResourceList()) {
// check if constraint is fulfilled, otherwise remember this illegal combination
if (!reqClause.checkUsing(request, resource)) {
info.setIllegal(request, impl, resource);
info.getIlpVariable(request, impl, resource).setIllegal(true);
}
}
}
}
// 2.2 Architecture constraints: One impl/resource and request
oneImplLhs.addIlpTerm(new IlpTerm(-1, info.getIlpVariable(request, impl)));
// implementation variable definition
result.addIlpConstraint(new IlpConstraint(request.getIlpName() + "_single_" + impl.getIlpName(),
oneImplLhs, ClauseComparator.EQ, 0));
// 2.3 NFP-Negotiation: Use implementations of required components
for (ComponentRequirement req : impl.getComponentRequirementList()) {
IlpLeftHandSide reqImplLhs = new IlpLeftHandSide();
for (Implementation reqImpl : req.getComponentRef().getRef().getImplementationList()) {
reqImplLhs.addIlpTerm(new IlpTerm(1, info.getIlpVariable(request, reqImpl)));
}
reqImplLhs.addIlpTerm(new IlpTerm(-1, info.getIlpVariable(request, impl)));
// 1c. required components
result.addIlpConstraint(new IlpConstraint(request.getIlpName() + "_" + impl.getIlpName() +
"_req_" + req.getComponentRef().getRef().getIlpName(),
reqImplLhs, ClauseComparator.GE, 0));
}
}
// 2.2 Architecture constraints: One impl per component and request
// 1b.
result.addIlpConstraint(new IlpConstraint(request.getIlpName() + "_opc_" + comp.getIlpName(),
oneCompLhs, ClauseComparator.LE, 1));
}
// 2.1.a Request constraints: Target component (i.e., use one of its implementations)
IlpLeftHandSide targetLhs = new IlpLeftHandSide();
for (Implementation impl : request.getTarget().getRef().getImplementationList()) {
IlpVariable var = info.getIlpVariable(request, impl);
targetLhs.addIlpTerm(new IlpTerm(1, var));
}
// 1a. functional requirement of the request
result.addIlpConstraint(new IlpConstraint(request.getIlpName() + "_target", targetLhs, ClauseComparator.EQ, 1));
// 2.1.b Request constraints: Required NFPs of target component
for (Clause requiredClause : request.getConstraintList()) {
IlpLeftHandSide reqLhs = new IlpLeftHandSide();
Property requiredProperty = requiredClause.getDesignator().asSoftwareDesignator().getPropertyRef().getRef();
......@@ -157,6 +156,7 @@ aspect ILP {
}
}
}
// 2a. non-functional requirement of the request
result.addIlpConstraint(new IlpConstraint(request.getIlpName() + "_req_" + requiredProperty.getIlpName(),
reqLhs, requiredClause.getClauseComparator(),
requiredClause.evalUsing(request, null)));
......@@ -174,25 +174,30 @@ aspect ILP {
// 2.2 Architecture constraints: Only one config per hardware resource
for (IlpConstraint constraint : info.resourceConstraints.values()) {
// 1d.
result.addIlpConstraint(constraint);
}
// Generals
// variables
for (IlpVariable var : info.vars.values()) {
result.addIlpVariable(var);
}
// Bounds (all binary except illegal which are zero)
info.vars.values().removeAll(info.illegal);
for (IlpVariable var : info.vars.values()) {
// TODO uncomment addIlpBound line. Comment out to not clutter output for the moment.
result.addIlpBound(new IlpBound(var, IlpBoundType.BINARY));
}
for (IlpVariable var : info.illegal) {
result.addIlpBound(new IlpBound(var, IlpBoundType.ZERO));
}
result.setInfo(info);
return result;
}
syn IlpVariable ILP.resolve(String variableName) {
return variableMap().get(variableName);
}
syn java.util.Map<String, IlpVariable> ILP.variableMap() {
java.util.Map<String, IlpVariable> variableMap = new java.util.HashMap();
for (IlpVariable variable : getIlpVariableList()) {
if (!variable.getIllegal()) {
variableMap.put(variable.getName(), variable);
}
}
return variableMap;
}
}
......@@ -7,14 +7,11 @@ aspect ILPPrinting {
for (IlpConstraint c : getIlpConstraintList()) {
result.append(c.printIlp()).lb();
}
result.append("Bounds").lb();
for (IlpBound b : getIlpBoundList()) {
result.append(b.printIlp()).lb();
}
// TODO check if "Generals" is always correct
result.append("Generals").lb();
result.append("Binary").lb();
for (IlpVariable v : getIlpVariableList()) {
result.append(v.getName()).append(" ");
if (!v.getIllegal()) {
result.append(v.getName()).append(" ");
}
}
return result.lb().append("End").lb();
}
......@@ -30,7 +27,12 @@ aspect ILPPrinting {
syn IlpString IlpConstraint.printIlp() {
IlpString result = new IlpString();
result.append(getName()).append(": ").append(getIlpLeftHandSide().printIlp()).append(" ");
IlpString lhs = getIlpLeftHandSide().printIlp();
if (lhs == null) {
return result;
}
result.append(getName()).append(": ").append(lhs).append(" ");
switch (getClauseComparator()) {
case LT: result.append("<"); break;
case LE: result.append("<="); break;
......@@ -42,20 +44,15 @@ aspect ILPPrinting {
return result.append(" ").append(getRightHandSide());
}
syn IlpString IlpBound.printIlp() {
IlpString result = new IlpString();
switch(getType()) {
case BINARY: result.append("0 <= ").append(getRef().getName()).append(" <= 1"); break;
case ZERO: result.append(getRef().getName()).append(" = 0"); break;
case GREATER_EQUAL_ZERO: result.append("0 <= ").append(getRef().getName()); break;
default: logger.error("Unknown IlpBound type {}", getType().toString());
}
return result;
}
syn IlpString IlpLeftHandSide.printIlp() {
IlpString result = new IlpString();
boolean printed = false;
for (IlpTerm t : getIlpTermList()) {
if (t.getRef().getIllegal()) {
continue;
} else {
printed = true;
}
if (t.getValue() >= 0) {
result.append(" +");
} else {
......@@ -68,7 +65,11 @@ aspect ILPPrinting {
}
result.append(" ").append(t.getRef().getName());
}
if (printed) {
return result;
} else {
return null;
}
}
}
\ No newline at end of file
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment