Commit a53e859d authored by Johannes Mey's avatar Johannes Mey
Browse files

some refactoring

parent 75f636cf
aspect Helpers {
public static void Clause.populateResourceMapping(ResourceMapping mapping, ResourceRequirement requirement, Resource resource) {
for (ResourceRequirement subRequirement : requirement.getResourceRequirementList()) {
int fittingResourceCount = 0;
for (int currentInstance = 0; currentInstance < subRequirement.getNumInstance(); currentInstance++) {
Instance instance = subRequirement.getInstance(currentInstance);
for (int currentResource = 0; currentResource < resource.getNumSubResource(); currentResource++) {
Resource subResource = resource.getSubResource(currentResource);
if (subResource.getType().getRef() == subRequirement.getResourceTypeRef().getRef()) {
if (currentInstance == fittingResourceCount) {
ResourceMapping newMapping = new ResourceMapping(instance, subResource, new de.tudresden.inf.st.mquat.jastadd.model.List<>());
mapping.addResourceMapping(newMapping);
populateResourceMapping(newMapping, subRequirement, subResource);
fittingResourceCount++;
}
currentInstance++;
}
}
}
}
}
uncache Clause.simpleAssignment(Request request, Resource resource);
syn Assignment Clause.simpleAssignment(Request request, Resource resource) {
Assignment assignment = new Assignment();
......@@ -31,7 +9,7 @@ aspect Helpers {
assignment.setImplementation(impl);
ResourceMapping mapping=new ResourceMapping(impl.getResourceRequirement().getInstance(0),resource,new de.tudresden.inf.st.mquat.jastadd.model.List<>());
populateResourceMapping(mapping,impl.getResourceRequirement(),resource);
Resource.populateResourceMapping(mapping,impl.getResourceRequirement(),resource);
assignment.setResourceMapping(mapping);
}
return assignment;
......@@ -42,6 +20,8 @@ aspect Helpers {
public Solution Root.createRandomSolution(java.util.Random random) {
Solution solution = new Solution();
solution.setModel(this);
// create a resource bucket
java.util.List<Resource> resourceList = populateResourceList(this.getHardwareModel().getResourceList(), new ArrayList<>());
......@@ -97,6 +77,8 @@ aspect Helpers {
} while (chosenResource.getType().getRef() != requiredResourceType);
mapping.setResource(resourceList.remove(resourceNumber));
Resource.populateResourceMapping(mapping, resourceRequirement, chosenResource);
assignment.setResourceMapping(mapping);
}
......
aspect SolverUtils {
public static void Resource.populateResourceMapping(ResourceMapping mapping, ResourceRequirement requirement, Resource resource) {
for (ResourceRequirement subRequirement : requirement.getResourceRequirementList()) {
int fittingResourceCount = 0;
for (int currentInstance = 0; currentInstance < subRequirement.getNumInstance(); currentInstance++) {
Instance instance = subRequirement.getInstance(currentInstance);
for (int currentResource = 0; currentResource < resource.getNumSubResource(); currentResource++) {
Resource subResource = resource.getSubResource(currentResource);
if (subResource.getType().getRef() == subRequirement.getResourceTypeRef().getRef()) {
if (currentInstance == fittingResourceCount) {
ResourceMapping newMapping = new ResourceMapping(instance, subResource, new de.tudresden.inf.st.mquat.jastadd.model.List<>());
mapping.addResourceMapping(newMapping);
populateResourceMapping(newMapping, subRequirement, subResource);
fittingResourceCount++;
}
currentInstance++;
}
}
}
}
}
}
\ No newline at end of file
......@@ -94,7 +94,7 @@ public class ACOSolver implements BenchmarkableSolver {
ResourceMapping mapping = new ResourceMapping(impl.getResourceRequirement().getInstance(0), resource,
new de.tudresden.inf.st.mquat.jastadd.model.List<>());
SolverUtils.populateResourceMapping(mapping, impl.getResourceRequirement(), resource);
Resource.populateResourceMapping(mapping, impl.getResourceRequirement(), resource);
assignment.setResourceMapping(mapping);
}
......
......@@ -46,7 +46,7 @@ public class Ant {
ResourceMapping mapping = new ResourceMapping(impl.getResourceRequirement().getInstance(0), resource,
new de.tudresden.inf.st.mquat.jastadd.model.List<>());
SolverUtils.populateResourceMapping(mapping, impl.getResourceRequirement(), resource);
Resource.populateResourceMapping(mapping, impl.getResourceRequirement(), resource);
assignment.setResourceMapping(mapping);
}
......
......@@ -51,7 +51,7 @@ public class EMFeRSolver implements BenchmarkableSolver {
Implementation impl = assignment.getImplementation();
ResourceMapping mapping = new ResourceMapping(impl.getResourceRequirement().getInstance(0), resource, new de.tudresden.inf.st.mquat.jastadd.model.List<>());
SolverUtils.populateResourceMapping(mapping, impl.getResourceRequirement(), resource);
Resource.populateResourceMapping(mapping, impl.getResourceRequirement(), resource);
assignment.setResourceMapping(mapping);
}
......
......@@ -104,7 +104,7 @@ public class EMFeRTrafos
Resource resource = findResource(eAssignment.getNodeName());
ResourceMapping resourceMapping = new ResourceMapping(instance, resource, new List<>());
SolverUtils.populateResourceMapping(resourceMapping, implementation.getResourceRequirement(), resource);
Resource.populateResourceMapping(resourceMapping, implementation.getResourceRequirement(), resource);
dAssignment.setResourceMapping(resourceMapping);
......@@ -154,7 +154,7 @@ public class EMFeRTrafos
{
Resource resource = findResource(eSubAssignment.getNodeName());
ResourceMapping resourceMapping = new ResourceMapping(instance, resource, new List<>());
SolverUtils.populateResourceMapping(resourceMapping, subImpl.getResourceRequirement(), resource);
Resource.populateResourceMapping(resourceMapping, subImpl.getResourceRequirement(), resource);
dSubAssignment.setResourceMapping(resourceMapping);
if (dSubAssignment.isValid())
......@@ -208,7 +208,7 @@ public class EMFeRTrafos
{
ResourceMapping resourceMapping = new ResourceMapping(instance, resource, new List<>());
SolverUtils.populateResourceMapping(resourceMapping, implementation.getResourceRequirement(), resource);
Resource.populateResourceMapping(resourceMapping, implementation.getResourceRequirement(), resource);
dAssignment.setResourceMapping(resourceMapping);
......@@ -251,7 +251,7 @@ public class EMFeRTrafos
for (Resource resource : availableResources)
{
ResourceMapping resourceMapping = new ResourceMapping(instance, resource, new List<>());
SolverUtils.populateResourceMapping(resourceMapping, subImpl.getResourceRequirement(), resource);
Resource.populateResourceMapping(resourceMapping, subImpl.getResourceRequirement(), resource);
dSubAssignment.setResourceMapping(resourceMapping);
if (dSubAssignment.isValid())
......
......@@ -40,7 +40,7 @@ public class SimpleSolver implements BenchmarkableSolver {
Implementation impl = assignment.getImplementation();
ResourceMapping mapping = new ResourceMapping(impl.getResourceRequirement().getInstance(0), resource, new de.tudresden.inf.st.mquat.jastadd.model.List<>());
SolverUtils.populateResourceMapping(mapping, impl.getResourceRequirement(), resource);
Resource.populateResourceMapping(mapping, impl.getResourceRequirement(), resource);
assignment.setResourceMapping(mapping);
}
......
......@@ -12,28 +12,6 @@ import java.util.concurrent.TimeUnit;
@SuppressWarnings("Duplicates")
public class SolverUtils {
public static void populateResourceMapping(ResourceMapping mapping, ResourceRequirement requirement, Resource resource) {
for (ResourceRequirement subRequirement : requirement.getResourceRequirementList()) {
int fittingResourceCount = 0;
for (int currentInstance = 0; currentInstance < subRequirement.getNumInstance(); currentInstance++) {
Instance instance = subRequirement.getInstance(currentInstance);
for (int currentResource = 0; currentResource < resource.getNumSubResource(); currentResource++) {
Resource subResource = resource.getSubResource(currentResource);
if (subResource.getType().getRef() == subRequirement.getResourceTypeRef().getRef()) {
if (currentInstance == fittingResourceCount) {
ResourceMapping newMapping = new ResourceMapping(instance, subResource, new de.tudresden.inf.st.mquat.jastadd.model.List<>());
mapping.addResourceMapping(newMapping);
populateResourceMapping(newMapping, subRequirement, subResource);
fittingResourceCount++;
}
currentInstance++;
}
}
}
}
}
public static long populateSolution(List<Assignment> listOfInitialAssignments, Solution result, Logger logger)
throws SolvingException {
StopWatch watch = StopWatch.start();
......@@ -44,7 +22,7 @@ public class SolverUtils {
Resource resource = assignment.getResource();
ResourceMapping mapping = new ResourceMapping(impl.getResourceRequirement().getInstance(0), resource, new de.tudresden.inf.st.mquat.jastadd.model.List<>());
populateResourceMapping(mapping, impl.getResourceRequirement(), resource);
Resource.populateResourceMapping(mapping, impl.getResourceRequirement(), resource);
assignment.setResourceMapping(mapping);
// for (ResourceRequirement rr : impl.getResourceRequirementList()) {
......
......@@ -97,6 +97,11 @@ public abstract class HandwrittenTestSuite {
}
collector.checkThat("Solution is not valid", true,
equalTo(modelAndSolution.getSecondElement().isValid()));
logger.info("completeness: " + modelAndSolution.getSecondElement().evaluateSoftwareCompleteness());
logger.info("sw-validity: " + modelAndSolution.getSecondElement().evaluateSoftwareValidity());
logger.info("validity: " + modelAndSolution.getSecondElement().evaluateValidity());
logger.info("objective: " + modelAndSolution.getSecondElement().computeObjective());
}
@Test
......
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