Skip to content
Snippets Groups Projects
Commit ac2070a5 authored by Albert Zuendorf's avatar Albert Zuendorf
Browse files

first running solution, almost as good as the simple solver (:

parent 0c86ca15
Branches
Tags
No related merge requests found
Showing with 640 additions and 182 deletions
...@@ -30,3 +30,4 @@ hs_err_pid* ...@@ -30,3 +30,4 @@ hs_err_pid*
.settings/ .settings/
.classpath .classpath
.project .project
results/
...@@ -34,7 +34,8 @@ The following steps need to be completed: ...@@ -34,7 +34,8 @@ The following steps need to be completed:
1. Add an include of your project to `settings.gradle` 1. Add an include of your project to `settings.gradle`
1. Optional step: Create a test case by extending the [`HandwrittenTestSuite`](https://git-st.inf.tu-dresden.de/stgroup/ttc18/blob/master/jastadd-mquat-solver/src/test/java/de/tudresden/inf/st/mquat/solving/HandwrittenTestSuite.java) 1. Optional step: Create a test case by extending the [`HandwrittenTestSuite`](https://git-st.inf.tu-dresden.de/stgroup/ttc18/blob/master/jastadd-mquat-solver/src/test/java/de/tudresden/inf/st/mquat/solving/HandwrittenTestSuite.java)
1. Add a compile dependency to your project in `build.gradle` of the project `jastadd-mquat-benchmark` 1. Add a compile dependency to your project in `build.gradle` of the project `jastadd-mquat-benchmark`
1. Update [`de.tudresden.inf.st.mquat.benchmark.SolverFactory.createAvailableSolversIfNeeded`](https://git-st.inf.tu-dresden.de/stgroup/ttc18/blob/master/jastadd-mquat-benchmark/src/main/java/de/tudresden/inf/st/mquat/benchmark/SolverFactory.java#L22) to create a new instance of your solver 1. Update [`de.tudresden.inf.st.mquat.benchmark.SolverFactory.createAvailableSolversIfNeeded`]
(https://git-st.inf.tu-dresden.de/stgroup/ttc18/blob/master/jastadd-mquat-benchmark/src/main/java/de/tudresden/inf/st/mquat/benchmark/SolverFactory.java#L22) to create a new instance of your solver
1. Add the name of your solver to the benchmark settings 1. Add the name of your solver to the benchmark settings
- Use `jastadd-mquat-benchmark/src/main/resources/scenarios.json` for the Gradle task `benchmarkFull` - Use `jastadd-mquat-benchmark/src/main/resources/scenarios.json` for the Gradle task `benchmarkFull`
- Use `jastadd-mquat-benchmark/src/main/resources/local-benchmark-settings.json` for the Gralde task `benchmarkCustom` (see [Custom Benchmark](#custom-benchmark) for details) - Use `jastadd-mquat-benchmark/src/main/resources/local-benchmark-settings.json` for the Gralde task `benchmarkCustom` (see [Custom Benchmark](#custom-benchmark) for details)
......
...@@ -11,6 +11,7 @@ dependencies { ...@@ -11,6 +11,7 @@ dependencies {
compile project(':jastadd-mquat-base') compile project(':jastadd-mquat-base')
compile project(':jastadd-mquat-solver') compile project(':jastadd-mquat-solver')
compile project(':jastadd-mquat-solver-ilp') compile project(':jastadd-mquat-solver-ilp')
compile project(':jastadd-mquat-solver-emfer')
compile project(':jastadd-mquat-solver-simple') compile project(':jastadd-mquat-solver-simple')
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.8.1' compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.8.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0' compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
...@@ -30,7 +31,7 @@ task benchmarkFull(type: JavaExec, dependsOn: assemble) { ...@@ -30,7 +31,7 @@ task benchmarkFull(type: JavaExec, dependsOn: assemble) {
classpath = sourceSets.test.runtimeClasspath classpath = sourceSets.test.runtimeClasspath
main = 'de.tudresden.inf.st.mquat.benchmark.FullBenchmarkMain' main = 'de.tudresden.inf.st.mquat.benchmark.FullBenchmarkMain'
systemProperty "java.library.path", project.glpkPath systemProperty "java.library.path", project.glpkPath
// jvmArgs("-Xmx=4096m") // jvmArgs("-Xmx=2g")
if (project.hasProperty("scenario")) { if (project.hasProperty("scenario")) {
args(scenario.split(',')) args(scenario.split(','))
} }
......
...@@ -4,6 +4,7 @@ import de.tudresden.inf.st.mquat.solving.BenchmarkableSolver; ...@@ -4,6 +4,7 @@ import de.tudresden.inf.st.mquat.solving.BenchmarkableSolver;
import de.tudresden.inf.st.mquat.solving.ilp.ILPDirectSolver; import de.tudresden.inf.st.mquat.solving.ilp.ILPDirectSolver;
import de.tudresden.inf.st.mquat.solving.ilp.ILPExternalSolver; import de.tudresden.inf.st.mquat.solving.ilp.ILPExternalSolver;
import de.tudresden.inf.st.mquat.solving.simple.SimpleSolver; import de.tudresden.inf.st.mquat.solving.simple.SimpleSolver;
import uniks.EMFeRSolver;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
...@@ -22,9 +23,10 @@ public class SolverFactory { ...@@ -22,9 +23,10 @@ public class SolverFactory {
private static Map<String, BenchmarkableSolver> createAvailableSolversIfNeeded() { private static Map<String, BenchmarkableSolver> createAvailableSolversIfNeeded() {
if (availableSolvers == null) { if (availableSolvers == null) {
availableSolvers = Stream.of( availableSolvers = Stream.of(
new ILPExternalSolver(), new EMFeRSolver(),
new ILPDirectSolver(), // new ILPExternalSolver(),
new SimpleSolver() new ILPDirectSolver(),
new SimpleSolver()
).collect(Collectors.toMap(BenchmarkableSolver::getName, Function.identity())); ).collect(Collectors.toMap(BenchmarkableSolver::getName, Function.identity()));
} }
return availableSolvers; return availableSolvers;
......
...@@ -2,11 +2,12 @@ ...@@ -2,11 +2,12 @@
"path": "results", "path": "results",
"logLevel": "info", "logLevel": "info",
"solvers": [ "solvers": [
"ilp-direct" "ilp-direct",
// "ilp-external", // "ilp-external",
// "simple" "emfer",
"simple"
], ],
"timeoutValue": 15, "timeoutValue": 2,
"timeoutUnit": "MINUTES", "timeoutUnit": "MINUTES",
"seed": 0, "seed": 0,
// "repetitions": 10, // "repetitions": 10,
...@@ -17,12 +18,12 @@ ...@@ -17,12 +18,12 @@
{ "id": 3, "name": "small-complex-sw", "variants": 2, "requests": 1, "depth": 5, "resources": 1.5 }, { "id": 3, "name": "small-complex-sw", "variants": 2, "requests": 1, "depth": 5, "resources": 1.5 },
{ "id": 4, "name": "medium", "variants": 10, "requests": 15, "depth": 2, "resources": 1.5 }, { "id": 4, "name": "medium", "variants": 10, "requests": 15, "depth": 2, "resources": 1.5 },
{ "id": 5, "name": "medium-many-hw", "variants": 10, "requests": 15, "depth": 2, "resources": 5 }, { "id": 5, "name": "medium-many-hw", "variants": 10, "requests": 15, "depth": 2, "resources": 5 },
{ "id": 6, "name": "medium-complex-sw", "variants": 5, "requests": 10, "depth": 5, "resources": 1.5 }, { "id": 6, "name": "medium-complex-sw", "variants": 5, "requests": 10, "depth": 5, "resources": 1.5 }
{ "id": 7, "name": "large", "variants": 20, "requests": 20, "depth": 2, "resources": 1.5 }, // { "id": 7, "name": "large", "variants": 20, "requests": 20, "depth": 2, "resources": 1.5 },
{ "id": 8, "name": "large-many-hw", "variants": 20, "requests": 20, "depth": 2, "resources": 5 }, // { "id": 8, "name": "large-many-hw", "variants": 20, "requests": 20, "depth": 2, "resources": 5 },
{ "id": 9, "name": "large-complex-sw", "variants": 10, "requests": 20, "depth": 5, "resources": 1.5 }, // { "id": 9, "name": "large-complex-sw", "variants": 10, "requests": 20, "depth": 5, "resources": 1.5 },
{ "id": 10, "name": "huge", "variants": 50, "requests": 50, "depth": 2, "resources": 1.5 }, // { "id": 10, "name": "huge", "variants": 50, "requests": 50, "depth": 2, "resources": 1.5 },
{ "id": 11, "name": "huge-many-hw", "variants": 50, "requests": 50, "depth": 2, "resources": 5 }, // { "id": 11, "name": "huge-many-hw", "variants": 50, "requests": 50, "depth": 2, "resources": 5 },
{ "id": 12, "name": "huge-complex-sw", "variants": 20, "requests": 50, "depth": 5, "resources": 1.5 } // { "id": 12, "name": "huge-complex-sw", "variants": 20, "requests": 50, "depth": 5, "resources": 1.5 }
] ]
} }
No preview for this file type
...@@ -6,210 +6,227 @@ import de.tudresden.inf.st.mquat.solving.Solver; ...@@ -6,210 +6,227 @@ import de.tudresden.inf.st.mquat.solving.Solver;
import de.tudresden.inf.st.mquat.solving.SolverUtils; import de.tudresden.inf.st.mquat.solving.SolverUtils;
import de.tudresden.inf.st.mquat.solving.SolvingException; import de.tudresden.inf.st.mquat.solving.SolvingException;
import de.tudresden.inf.st.mquat.utils.StopWatch; import de.tudresden.inf.st.mquat.utils.StopWatch;
import emfer.EMFeR;
import emfer.reachability.ReachableState;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EcorePackage;
import uniks.ttc18.EAssignment; import uniks.ttc18.EAssignment;
import uniks.ttc18.ESolution; import uniks.ttc18.ESolution;
import uniks.ttc18.Ttc18Factory; import uniks.ttc18.Ttc18Factory;
import java.util.*;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.Stack;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class EMFeRSolver implements BenchmarkableSolver { public class EMFeRSolver implements BenchmarkableSolver {
private static final Logger logger = LogManager.getLogger(EMFeRSolver.class); private static final Logger logger = LogManager.getLogger(EMFeRSolver.class);
private Solution lastSolution; private Solution lastSolution;
private long lastSolvingTime; private long lastSolvingTime;
private int solutionCounter; private int solutionCounter;
private StopWatch stopWatch; private StopWatch stopWatch;
private long maxSolvingTime; private long maxSolvingTime;
private boolean timedOut; private boolean timedOut;
public EMFeRSolver() { public EMFeRSolver() {
this(Long.MAX_VALUE); this(Long.MAX_VALUE);
} }
public EMFeRSolver(long maxSolvingTime) { public EMFeRSolver(long maxSolvingTime) {
this.maxSolvingTime = maxSolvingTime; this.maxSolvingTime = maxSolvingTime;
reset(); reset();
} }
private static void assignResource(Assignment assignment, Resource resource) { private static void assignResource(Assignment assignment, Resource resource) {
Implementation impl = assignment.getImplementation(); Implementation impl = assignment.getImplementation();
ResourceMapping mapping = new ResourceMapping(impl.getResourceRequirement().getInstance(0), resource, new de.tudresden.inf.st.mquat.jastadd.model.List<>()); ResourceMapping mapping = new ResourceMapping(impl.getResourceRequirement().getInstance(0), resource, new de.tudresden.inf.st.mquat.jastadd.model.List<>());
SolverUtils.populateResourceMapping(mapping, impl.getResourceRequirement(), resource); SolverUtils.populateResourceMapping(mapping, impl.getResourceRequirement(), resource);
assignment.setResourceMapping(mapping); assignment.setResourceMapping(mapping);
} }
private int checkAssignment(Solution solution, List<Solution> solutions, List<Assignment> assignments, List<Set<Resource>> possibleResources, int index, Stack<Resource> usedResources) { private int checkAssignment(Solution solution, List<Solution> solutions, List<Assignment> assignments, List<Set<Resource>> possibleResources, int index, Stack<Resource> usedResources) {
int checkCounter = 0; int checkCounter = 0;
Assignment assignment = assignments.get(index); Assignment assignment = assignments.get(index);
for (Resource resource : possibleResources.get(index)) { for (Resource resource : possibleResources.get(index)) {
if (stopWatch.time(TimeUnit.MILLISECONDS) > maxSolvingTime) { if (stopWatch.time(TimeUnit.MILLISECONDS) > maxSolvingTime) {
return checkCounter; return checkCounter;
} }
if (usedResources.contains(resource)) continue;
assignResource(assignment, resource);
usedResources.push(resource);
checkCounter++;
if (index == assignments.size() - 1) {
if (solution.isValid()) {
solutionCounter++;
if (solutions.isEmpty() || solution.computeObjective() < solutions.get(solutions.size() - 1).computeObjective()) {
Solution clone = solution.deepCopy();
solutions.add(clone);
logger.info("found a better solution with an objective of {}.", solution.computeObjective());
}
}
} else {
checkCounter += checkAssignment(solution, solutions, assignments, possibleResources, index + 1, usedResources);
}
usedResources.pop();
}
return checkCounter;
}
@Override if (usedResources.contains(resource)) continue;
public Solution solve(Root model) throws SolvingException { assignResource(assignment, resource);
reset(); usedResources.push(resource);
if (model.getNumRequest() == 0) { checkCounter++;
return Solution.emptySolutionOf(model); if (index == assignments.size() - 1) {
} if (solution.isValid()) {
solutionCounter++;
if (solutions.isEmpty() || solution.computeObjective() < solutions.get(solutions.size() - 1).computeObjective()) {
Solution clone = solution.deepCopy();
solutions.add(clone);
logger.info("found a better solution with an objective of {}.", solution.computeObjective());
}
ESolution eSolution = Ttc18Factory.eINSTANCE.createESolution(); }
} else {
checkCounter += checkAssignment(solution, solutions, assignments, possibleResources, index + 1, usedResources);
}
usedResources.pop();
}
return checkCounter;
}
EMFeRTrafos emFeRTrafos = new EMFeRTrafos(model); @Override
public Solution solve(Root model) throws SolvingException
{
stopWatch = StopWatch.start();
emFeRTrafos.createTopLevelAssignments(eSolution); EMFeRTrafos emFeRTrafos = new EMFeRTrafos(model);
for (EAssignment topAssignment : eSolution.getAssignments()) ESolution eSolution = Ttc18Factory.eINSTANCE.createESolution();
{ emFeRTrafos.createTopLevelAssignments(eSolution);
emFeRTrafos.createSubAssignments(eSolution, topAssignment);
}
int numAssignments = 0; EDataType eString = EcorePackage.eINSTANCE.getEString();
int numSoftwareSolutions = 0; EObject eObj = null;
int numTotalSoftwareSolutions = 0;
stopWatch = StopWatch.start(); // HashMap<String, Collection<String>> implementation2NodeListMap = emFeRTrafos.computeImplementation2NodeListMap();
List<Solution> solutions = new ArrayList<>(); EMFeR emfer = new EMFeR()
.withStart(eSolution)
.withMaxNoOfNewStates(100 * 1000)
.withMetric(root -> -1 * emFeRTrafos.getNumberOfOpenIssues(root))
.withTrafo("choose implementation", root -> emFeRTrafos.getImplementationChoices(root), (root, impl) -> emFeRTrafos.applyImplementationChoice(root, impl))
.withTrafo("assign node", root -> emFeRTrafos.getComputeNodeChoices(root), (root, node) -> emFeRTrafos.assignComputeNode(root, node))
;
// iterate all possible assignments int noOfStates = emfer.explore();
// Note, that this only considers assignments of one configuration to each hardware component
Solution bestSolution = null;
double bestObjective = Double.MAX_VALUE;
int noOfCompleteSolutions = 0;
Solution currentSolution = Solution.createSoftwareSolution(model); System.out.println("emfer searching for best solution in " + noOfStates);
Solution emferSolution = emFeRTrafos.transform(eSolution); for (ReachableState state : emfer.getReachabilityGraph().getStates())
{
ESolution newSolution = (ESolution) state.getRoot();
boolean valid = emferSolution.isValid(); if (bestSolution == null)
// currentSolution = emferSolution; {
// currentSolution.trace().process(new LoggerProcessor()); bestSolution = emFeRTrafos.transformPartial(newSolution);
}
logger.info("emfer found a solution with an objective of {}.", emferSolution.computeObjective()); if (emFeRTrafos.getNumberOfOpenIssues(newSolution) == 0)
{
noOfCompleteSolutions ++;
Solution emferSolution = emFeRTrafos.transformPartial(newSolution);
de.tudresden.inf.st.mquat.jastadd.model.List<Resource> resources = model.getHardwareModel().getResources(); if ( ! emferSolution.isValid())
{
// System.out.println("solution is invalid: " + newSolution);
continue;
}
boolean hasNextSoftwareAssignment; double newObjective = emferSolution.computeObjective();
do {
numTotalSoftwareSolutions++; // System.out.println("objective " + newObjective + "\n" + newSolution);
if (newObjective < bestObjective)
{
bestSolution = emferSolution;
bestObjective = newObjective;
System.out.println("Found solution with objective: " + bestObjective);
}
}
}
if (currentSolution.isSoftwareValid()) { if (bestSolution != null)
{
logger.info("emfer found a solution with an objective of {}. Number of complete solutions {} ", bestSolution.computeObjective(), noOfCompleteSolutions );
}
numSoftwareSolutions++; lastSolvingTime = stopWatch.time(TimeUnit.MILLISECONDS);
List<Assignment> assignments = currentSolution.allAssignments(); return bestSolution;
}
// initialize the lists of possible assignments private boolean isCompleteSolution(ESolution eSolution)
List<Set<Resource>> possibleResources = new ArrayList<>(assignments.size()); {
for (EAssignment eAssignment : eSolution.getAssignments())
{
if ( ! isCompleteSolution(eAssignment))
{
return false;
}
}
for (Assignment assignment : assignments) { return true;
Set<Resource> resourceList = new HashSet<>(); }
for (Resource resource : resources) {
// assignResource(assignment, resource); private boolean isCompleteSolution(EAssignment eAssignment)
if (assignment.isValid()) { {
resourceList.add(resource); if (eAssignment.getImplName() != null && eAssignment.getNodeName() != null)
{
for (EAssignment kid : eAssignment.getAssignments())
{
if ( ! isCompleteSolution(kid))
{
return false;
} }
} }
possibleResources.add(resourceList);
}
numAssignments += checkAssignment(currentSolution, solutions, assignments, possibleResources, 0, new Stack<>()); return true;
} }
else
if (stopWatch.time(TimeUnit.MILLISECONDS) > maxSolvingTime) { {
this.timedOut = true; return false;
logger.warn("Timeout! Solving terminated!");
break;
} }
}
hasNextSoftwareAssignment = currentSolution.nextSoftwareAssignment();
} while (hasNextSoftwareAssignment);
private void reset() {
logger.info("Number of total software solutions: {}", numTotalSoftwareSolutions); this.lastSolution = null;
logger.info("Number of iterated software solutions: {}", numSoftwareSolutions); this.solutionCounter = 0;
logger.info("Number of iterated solutions: {}", numAssignments); this.lastSolvingTime = 0;
logger.info("Number of correct solutions: {}", solutionCounter); this.timedOut = false;
}
if (solutions.size() > 0) {
lastSolution = solutions.get(solutions.size() - 1); @Override
} else { public String getName() {
lastSolution = Solution.emptySolutionOf(model); return "emfer";
logger.warn("Found no solution!"); }
}
@Override
lastSolvingTime = stopWatch.time(TimeUnit.MILLISECONDS); public long getLastSolvingTime() {
return lastSolvingTime;
return lastSolution; }
}
@Override
private void reset() { public double getLastObjective() {
this.lastSolution = null; if (lastSolution != null) {
this.solutionCounter = 0; return lastSolution.computeObjective();
this.lastSolvingTime = 0; } else {
this.timedOut = false; // TODO throw exception or do something reasonable
} return 0d;
}
@Override }
public String getName() {
return "simple"; @Override
} public Solver setTimeout(long timeoutValue, TimeUnit timeoutUnit) {
this.maxSolvingTime = timeoutUnit.toMillis(timeoutValue);
@Override return this;
public long getLastSolvingTime() { }
return lastSolvingTime;
} @Override
public boolean hadTimeout() {
@Override return this.timedOut;
public double getLastObjective() { }
if (lastSolution != null) {
return lastSolution.computeObjective();
} else {
// TODO throw exception or do something reasonable
return 0d;
}
}
@Override
public Solver setTimeout(long timeoutValue, TimeUnit timeoutUnit) {
this.maxSolvingTime = timeoutUnit.toMillis(timeoutValue);
return this;
}
@Override
public boolean hadTimeout() {
return this.timedOut;
}
} }
package uniks; package uniks;
import de.tudresden.inf.st.mquat.jastadd.model.*; import de.tudresden.inf.st.mquat.jastadd.model.*;
import de.tudresden.inf.st.mquat.jastadd.model.List;
import de.tudresden.inf.st.mquat.solving.SolverUtils; import de.tudresden.inf.st.mquat.solving.SolverUtils;
import org.eclipse.emf.ecore.EObject;
import uniks.ttc18.EAssignment; import uniks.ttc18.EAssignment;
import uniks.ttc18.EChoice;
import uniks.ttc18.ESolution; import uniks.ttc18.ESolution;
import uniks.ttc18.Ttc18Factory; import uniks.ttc18.Ttc18Factory;
import java.util.ArrayList; import java.util.*;
public class EMFeRTrafos public class EMFeRTrafos
{ {
...@@ -37,9 +40,9 @@ public class EMFeRTrafos ...@@ -37,9 +40,9 @@ public class EMFeRTrafos
EAssignment topAssignment = Ttc18Factory.eINSTANCE.createEAssignment(); EAssignment topAssignment = Ttc18Factory.eINSTANCE.createEAssignment();
topAssignment.setRequestName(requName); topAssignment.setRequestName(requName);
topAssignment.setCompName(targetName.toString()); topAssignment.setCompName(targetName.toString());
String nodeName = model.getHardwareModel().getResource(resourceNum).getName().toString(); // String nodeName = model.getHardwareModel().getResource(resourceNum).getName().toString();
resourceNum++; // resourceNum++;
topAssignment.setNodeName(nodeName); // topAssignment.setNodeName(nodeName);
assignments.add(topAssignment); assignments.add(topAssignment);
} }
} }
...@@ -71,6 +74,100 @@ public class EMFeRTrafos ...@@ -71,6 +74,100 @@ public class EMFeRTrafos
} }
public Solution transformPartial(ESolution eSolution)
{
Solution result = new Solution();
result.setModel(model);
// top level
for (EAssignment eAssignment : eSolution.getAssignments())
{
Assignment dAssignment = new Assignment();
Request request = findRequest(eAssignment.getRequestName());
dAssignment.setRequest(request);
dAssignment.setTopLevel(true);
Component comp = findComp(model, eAssignment.getCompName());
Implementation implementation = findImplementation(comp, eAssignment.getImplName());
dAssignment.setImplementation(implementation);
if (eAssignment.getNodeName() == null)
{
continue;
}
transformPartialSubAssignments(dAssignment, eAssignment, implementation);
for (Instance instance : implementation.getResourceRequirement().getInstances())
{
Resource resource = findResource(eAssignment.getNodeName());
ResourceMapping resourceMapping = new ResourceMapping(instance, resource, new List<>());
SolverUtils.populateResourceMapping(resourceMapping, implementation.getResourceRequirement(), resource);
dAssignment.setResourceMapping(resourceMapping);
// if (dAssignment.isValid())
// {
// System.out.println("assignment is valid " + dAssignment.getImplementation().getName() + " on " + resource.getName());
// }
}
result.addAssignment(dAssignment);
}
return result;
}
private void transformPartialSubAssignments(Assignment dAssignment, EAssignment eAssignment, Implementation implementation)
{
for (EAssignment eSubAssignment : eAssignment.getAssignments())
{
ComponentMapping componentMapping = new ComponentMapping();
Assignment dSubAssignment = new Assignment();
Request request = dAssignment.getRequest();
dSubAssignment.setRequest(request);
dSubAssignment.setTopLevel(false);
Component subComp = findComp(model, eSubAssignment.getCompName());
Implementation subImpl = findImplementation(subComp, eSubAssignment.getImplName());
dSubAssignment.setImplementation(subImpl);
Instance theInstance = findInstance(implementation, "the_" + eSubAssignment.getCompName());
componentMapping.setInstance(theInstance);
componentMapping.setAssignment(dSubAssignment);
dAssignment.getComponentMappings().add(componentMapping);
transformSubAssignments(dSubAssignment, eSubAssignment, subImpl);
if (eSubAssignment.getNodeName() == null)
{
continue;
}
for (Instance instance : subImpl.getResourceRequirement().getInstances())
{
Resource resource = findResource(eSubAssignment.getNodeName());
ResourceMapping resourceMapping = new ResourceMapping(instance, resource, new List<>());
SolverUtils.populateResourceMapping(resourceMapping, subImpl.getResourceRequirement(), resource);
dSubAssignment.setResourceMapping(resourceMapping);
if (dSubAssignment.isValid())
{
break;
}
}
}
}
ArrayList<Resource> availableResources = null; ArrayList<Resource> availableResources = null;
public Solution transform(ESolution eSolution) public Solution transform(ESolution eSolution)
...@@ -97,6 +194,10 @@ public class EMFeRTrafos ...@@ -97,6 +194,10 @@ public class EMFeRTrafos
Component comp = findComp(model, eAssignment.getCompName()); Component comp = findComp(model, eAssignment.getCompName());
Implementation implementation = findImplementation(comp, eAssignment.getImplName()); Implementation implementation = findImplementation(comp, eAssignment.getImplName());
if (implementation == null)
{
continue;
}
dAssignment.setImplementation(implementation); dAssignment.setImplementation(implementation);
transformSubAssignments(dAssignment, eAssignment, implementation); transformSubAssignments(dAssignment, eAssignment, implementation);
...@@ -139,7 +240,10 @@ public class EMFeRTrafos ...@@ -139,7 +240,10 @@ public class EMFeRTrafos
Component subComp = findComp(model, eSubAssignment.getCompName()); Component subComp = findComp(model, eSubAssignment.getCompName());
Implementation subImpl = findImplementation(subComp, eSubAssignment.getImplName()); Implementation subImpl = findImplementation(subComp, eSubAssignment.getImplName());
if (subImpl == null)
{
continue;
}
dSubAssignment.setImplementation(subImpl); dSubAssignment.setImplementation(subImpl);
for (Instance instance : subImpl.getResourceRequirement().getInstances()) for (Instance instance : subImpl.getResourceRequirement().getInstances())
...@@ -234,4 +338,335 @@ public class EMFeRTrafos ...@@ -234,4 +338,335 @@ public class EMFeRTrafos
} }
return null; return null;
} }
public Collection<EAssignment> getOpenAssignments(ESolution eSolution)
{
ArrayList<EAssignment> result = new ArrayList<>();
for (EAssignment eAssignment : eSolution.getAssignments())
{
if (eAssignment.getImplName() == null)
{
result.add(eAssignment);
}
getOpenSubAssignments(eAssignment, result);
}
return result;
}
private void getOpenSubAssignments(EAssignment eAssignment, ArrayList<EAssignment> result)
{
for (EAssignment subAssignment : eAssignment.getAssignments())
{
if (subAssignment.getImplName() == null)
{
result.add(subAssignment);
}
getOpenSubAssignments(subAssignment, result);
}
}
public Collection<EObject> getImplementationChoices(EObject root)
{
ArrayList<EObject> result = new ArrayList<>();
ESolution eSolution = (ESolution) root;
for (EAssignment eAssignment : getOpenAssignments(eSolution))
{
Component comp = findComp(model, eAssignment.getCompName());
for (Implementation dImpl : comp.getImplementations())
{
EChoice eImpl = Ttc18Factory.eINSTANCE.createEChoice();
eImpl.setAssignment(eAssignment);
eImpl.setResName(dImpl.getName().toString());
result.add(eImpl);
}
return result;
}
return result;
}
public void applyImplementationChoice(EObject root, EObject handle)
{
EChoice eImpl = (EChoice) handle;
EAssignment topAssignment = eImpl.getAssignment();
topAssignment.setImplName(eImpl.getResName());
Component comp = findComp(model, topAssignment.getCompName());
Implementation dImpl = findImplementation(comp, eImpl.getResName());
for (ComponentRequirement componentRequirement : dImpl.getComponentRequirementList())
{
String kidCompName = componentRequirement.getComponentRef().getRef().getName().toString();
EAssignment kidAssignment = Ttc18Factory.eINSTANCE.createEAssignment();
kidAssignment.setRequestName(topAssignment.getRequestName());
kidAssignment.setCompName(kidCompName);
topAssignment.getAssignments().add(kidAssignment);
}
}
public Collection getComputeNodeChoices(EObject root)
{
ESolution eSolution = (ESolution) root;
ArrayList<EChoice> result = new ArrayList<>();
// find assignment that is ready to be deployed
EAssignment eAssignment = getNextUndeployedAssignment(eSolution);
if (eAssignment == null)
{
return result;
}
HashSet<String> alreadInUseComputeNodes = getAlreadInUseComputeNodes(eSolution);
// loop through all compute nodes
for (Resource compNode : model.getHardwareModel().getResourceList())
{
String compNodeName = compNode.getName().toString();
// if (alreadInUseComputeNodes.contains(compNodeName))
// {
// continue;
// }
eAssignment.setNodeName(compNodeName);
// create dSolution
Solution dSolution = transformPartial(eSolution);
// if assignment is valid, add choice
boolean allValid = checkAssignments(dSolution);
if (allValid)
{
EChoice eChoice = Ttc18Factory.eINSTANCE.createEChoice();
eChoice.setAssignment(eAssignment);
eChoice.setResName(compNodeName);
result.add(eChoice);
// if (result.size() >= 4)
// {
// break;
// }
}
}
eAssignment.setNodeName(null);
if (result.size() == 0)
{
System.out.println("did not find hardware for \n" + eAssignment);
}
return result;
}
private boolean checkAssignments(Solution dSolution)
{
for (Assignment dAssignment : dSolution.getAssignmentList())
{
if (dAssignment.getResource() != null)
{
if (dAssignment.isValid())
{
// check kids
checkAssignments(dAssignment);
}
else
{
return false;
}
}
}
return true;
}
private boolean checkAssignments(Assignment parent)
{
for (ComponentMapping componentMapping : parent.getComponentMappingList())
{
Assignment dAssignment = componentMapping.getAssignment();
if (dAssignment.getResourceMapping() != null && dAssignment.getResource() != null)
{
if (dAssignment.isValid())
{
// check kids
checkAssignments(dAssignment);
}
else
{
return false;
}
}
}
return true;
}
private EAssignment getNextUndeployedAssignment(ESolution eSolution)
{
for (EAssignment eAssignment : eSolution.getAssignments())
{
if ( ! allAssignmentsInTreeHaveAnImplementation(eAssignment))
{
continue;
}
if (eAssignment.getNodeName() == null)
{
return eAssignment;
}
EAssignment kid = getNextUndeployedAssignment(eAssignment);
if (kid != null)
{
return kid;
}
}
return null;
}
private boolean allAssignmentsInTreeHaveAnImplementation(EAssignment eAssignment)
{
if (eAssignment.getImplName() == null)
{
return false;
}
for (EAssignment kid : eAssignment.getAssignments())
{
if (! allAssignmentsInTreeHaveAnImplementation(kid))
{
return false;
}
}
return true;
}
private EAssignment getNextUndeployedAssignment(EAssignment eAssignment)
{
for (EAssignment kid : eAssignment.getAssignments())
{
if (kid.getImplName() == null)
{
continue;
}
if (kid.getNodeName() == null)
{
return kid;
}
EAssignment grandKid = getNextUndeployedAssignment(kid);
if (grandKid != null)
{
return grandKid;
}
}
return null;
}
private HashSet<String> getAlreadInUseComputeNodes(ESolution eSolution)
{
HashSet<String> result = new HashSet<>();
for (EAssignment eAssignment : eSolution.getAssignments())
{
getAlreadInUseComputeNodes(eAssignment, result);
}
return result;
}
private void getAlreadInUseComputeNodes(EAssignment eAssignment, Set<String> alreadInUseComputeNodes)
{
if (eAssignment.getNodeName() != null)
{
alreadInUseComputeNodes.add(eAssignment.getNodeName());
}
for (EAssignment kidAssignment : eAssignment.getAssignments())
{
getAlreadInUseComputeNodes(kidAssignment, alreadInUseComputeNodes);
}
}
private Collection<EAssignment> getNoComputeNodeAssignments(ESolution eSolution)
{
ArrayList<EAssignment> result = new ArrayList<>();
for (EAssignment eAssignment : eSolution.getAssignments())
{
if (eAssignment.getNodeName() == null)
{
result.add(eAssignment);
}
getOpenSubAssignments(eAssignment, result);
}
return result;
}
public void assignComputeNode(EObject root, EObject node)
{
EChoice eChoice = (EChoice) node;
eChoice.getAssignment().setNodeName(eChoice.getResName());
}
public double getNumberOfOpenIssues(EObject root)
{
ESolution eSolution = (ESolution) root;
int result = 0;
for (EAssignment eAssignment : eSolution.getAssignments())
{
result += getNumberOfAssignmentOpenIssues(eAssignment);
}
return result;
}
private int getNumberOfAssignmentOpenIssues(EAssignment eAssignment)
{
int result = 0;
if (eAssignment.getImplName() == null) result++;
if (eAssignment.getNodeName() == null) result++;
for (EAssignment kid : eAssignment.getAssignments())
{
result += getNumberOfAssignmentOpenIssues(kid);
}
return result;
}
} }
...@@ -40,11 +40,12 @@ public class EMFeRSolverTest { ...@@ -40,11 +40,12 @@ public class EMFeRSolverTest {
int nfp = 0; int nfp = 0;
int req = 3; int req = 3;
int cpu = 1; int cpu = 1;
int seed = 0; int seed = 1;
ScenarioGenerator generator = new ScenarioGenerator(new ScenarioDescription(tlc, iac, isd, cac, csd, dep, imp, res, req, cpu, seed)); ScenarioGenerator generator = new ScenarioGenerator(new ScenarioDescription(tlc, iac, isd, cac, csd, dep, imp, res, req, cpu, seed));
Root model = generator.generate(); Root model = generator.generate();
EMFeRSolver solver = new EMFeRSolver(20000); EMFeRSolver solver = new EMFeRSolver(20000);
Solution solution = solver.solve(model); Solution solution = solver.solve(model);
......
...@@ -37,7 +37,7 @@ public class SimpleSolverTest { ...@@ -37,7 +37,7 @@ public class SimpleSolverTest {
int nfp = 0; int nfp = 0;
int req = 3; int req = 3;
int cpu = 1; int cpu = 1;
int seed = 0; int seed = 1;
ScenarioGenerator generator = new ScenarioGenerator(new ScenarioDescription(tlc, iac, isd, cac, csd, dep, imp, res, req, cpu, seed)); ScenarioGenerator generator = new ScenarioGenerator(new ScenarioDescription(tlc, iac, isd, cac, csd, dep, imp, res, req, cpu, seed));
......
...@@ -4,7 +4,6 @@ include ':jastadd-mquat-base' ...@@ -4,7 +4,6 @@ include ':jastadd-mquat-base'
include ':jastadd-mquat-benchmark' include ':jastadd-mquat-benchmark'
include ':jastadd-mquat-solver' include ':jastadd-mquat-solver'
include ':jastadd-mquat-solver-ilp' include ':jastadd-mquat-solver-ilp'
include ':jastadd-mquat-solver-simple'
include ':jastadd-mquat-solver-emfer' include ':jastadd-mquat-solver-emfer'
include 'jastadd-mquat-solver-emfer' include ':jastadd-mquat-solver-simple'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment