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

first solution generated

parent 8376ae35
Branches
Tags
No related merge requests found
No preview for this file type
......@@ -8,7 +8,7 @@ import de.tudresden.inf.st.mquat.solving.SolvingException;
import de.tudresden.inf.st.mquat.utils.StopWatch;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import uniks.ttc18.ECompMapping;
import uniks.ttc18.EAssignment;
import uniks.ttc18.ESolution;
import uniks.ttc18.Ttc18Factory;
......@@ -90,11 +90,11 @@ public class EMFeRSolver implements BenchmarkableSolver {
EMFeRTrafos emFeRTrafos = new EMFeRTrafos(model);
emFeRTrafos.createTopLevelMappings(eSolution);
emFeRTrafos.createTopLevelAssignments(eSolution);
for (ECompMapping compMapping : eSolution.getCompMappings())
for (EAssignment topAssignment : eSolution.getAssignments())
{
emFeRTrafos.createAssignments(eSolution, compMapping);
emFeRTrafos.createSubAssignments(eSolution, topAssignment);
}
int numAssignments = 0;
......@@ -113,8 +113,12 @@ public class EMFeRSolver implements BenchmarkableSolver {
Solution emferSolution = emFeRTrafos.transform(eSolution);
boolean valid = emferSolution.isValid();
// currentSolution = emferSolution;
// currentSolution.trace().process(new LoggerProcessor());
logger.info("emfer found a solution with an objective of {}.", emferSolution.computeObjective());
de.tudresden.inf.st.mquat.jastadd.model.List<Resource> resources = model.getHardwareModel().getResources();
boolean hasNextSoftwareAssignment;
......@@ -134,7 +138,7 @@ public class EMFeRSolver implements BenchmarkableSolver {
for (Assignment assignment : assignments) {
Set<Resource> resourceList = new HashSet<>();
for (Resource resource : resources) {
assignResource(assignment, resource);
// assignResource(assignment, resource);
if (assignment.isValid()) {
resourceList.add(resource);
}
......
package uniks;
import de.tudresden.inf.st.mquat.jastadd.model.*;
import de.tudresden.inf.st.mquat.solving.SolverUtils;
import uniks.ttc18.EAssignment;
import uniks.ttc18.ECompMapping;
import uniks.ttc18.ESolution;
import uniks.ttc18.Ttc18Factory;
import java.io.IOException;
import java.nio.file.*;
import java.util.ArrayList;
public class EMFeRTrafos
{
......@@ -18,11 +17,13 @@ public class EMFeRTrafos
this.model = model;
}
public void createTopLevelMappings(ESolution eSolution)
public int resourceNum = 0;
public void createTopLevelAssignments(ESolution eSolution)
{
org.eclipse.emf.common.util.EList<ECompMapping> compMappings = eSolution.getCompMappings();
org.eclipse.emf.common.util.EList<EAssignment> assignments = eSolution.getAssignments();
if ( ! compMappings.isEmpty())
if ( ! assignments.isEmpty())
{
return;
}
......@@ -33,38 +34,141 @@ public class EMFeRTrafos
ComponentRef target = request.getTarget();
Name targetName = target.getName();
ECompMapping eCompMapping = Ttc18Factory.eINSTANCE.createECompMapping();
eCompMapping.setRequName(requName);
eCompMapping.setCompName(targetName.toString());
compMappings.add(eCompMapping);
EAssignment topAssignment = Ttc18Factory.eINSTANCE.createEAssignment();
topAssignment.setRequestName(requName);
topAssignment.setCompName(targetName.toString());
String nodeName = model.getHardwareModel().getResource(resourceNum).getName().toString();
resourceNum++;
topAssignment.setNodeName(nodeName);
assignments.add(topAssignment);
}
}
public void createAssignments(ESolution eSolution, ECompMapping compMapping)
public void createSubAssignments(ESolution eSolution, EAssignment newAssignment)
{
String compName = compMapping.getCompName();
String compName = newAssignment.getCompName();
Component comp = findComp(model, compName);
Implementation implementation = comp.getImplementation(0);
EAssignment eAssignment = Ttc18Factory.eINSTANCE.createEAssignment();
String implName = implementation.getName().toString();
eAssignment.setImplName(implName);
compMapping.setAssignment(eAssignment);
newAssignment.setImplName(implName);
for (ComponentRequirement componentRequirement : implementation.getComponentRequirements())
{
String requCompName = componentRequirement.getComponentRef().getRef().getName().toString();
ECompMapping subMapping = Ttc18Factory.eINSTANCE.createECompMapping();
subMapping.setRequName(implName);
subMapping.setCompName(requCompName);
eAssignment.getCompMappings().add(subMapping);
EAssignment kidAssignment = Ttc18Factory.eINSTANCE.createEAssignment();
kidAssignment.setRequestName(implName);
kidAssignment.setCompName(requCompName);
String nodeName = model.getHardwareModel().getResource(resourceNum).getName().toString();
resourceNum++;
kidAssignment.setNodeName(nodeName);
newAssignment.getAssignments().add(kidAssignment);
createSubAssignments(eSolution, kidAssignment);
}
}
ArrayList<Resource> availableResources = null;
public Solution transform(ESolution eSolution)
{
Solution result = new Solution();
result.setModel(model);
availableResources = new ArrayList();
List<Resource> resourceList = model.getHardwareModel().getResources();
for (Resource r : resourceList)
{
availableResources.add(r);
}
// 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);
createAssignments(eSolution, subMapping);
transformSubAssignments(dAssignment, eAssignment, implementation);
for (Instance instance : implementation.getResourceRequirement().getInstances())
{
for (Resource resource : availableResources)
{
ResourceMapping resourceMapping = new ResourceMapping(instance, resource, new List<>());
SolverUtils.populateResourceMapping(resourceMapping, implementation.getResourceRequirement(), resource);
dAssignment.setResourceMapping(resourceMapping);
if (dAssignment.isValid())
{
availableResources.remove(resource);
break;
}
}
}
result.addAssignment(dAssignment);
}
return result;
}
private void transformSubAssignments(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);
for (Instance instance : subImpl.getResourceRequirement().getInstances())
{
for (Resource resource : availableResources)
{
ResourceMapping resourceMapping = new ResourceMapping(instance, resource, new List<>());
SolverUtils.populateResourceMapping(resourceMapping, subImpl.getResourceRequirement(), resource);
dSubAssignment.setResourceMapping(resourceMapping);
if (dSubAssignment.isValid())
{
availableResources.remove(resource);
break;
}
}
}
Instance instance = findInstance(implementation, "the_" + eSubAssignment.getCompName());
componentMapping.setInstance(instance);
componentMapping.setAssignment(dSubAssignment);
dAssignment.getComponentMappings().add(componentMapping);
transformSubAssignments(dSubAssignment, eSubAssignment, subImpl);
}
}
private Component findComp(Root model, String compName)
{
for (Component comp : model.getSoftwareModel().getComponents())
......@@ -77,23 +181,46 @@ public class EMFeRTrafos
return null;
}
public Solution transform(ESolution eSolution)
{
Solution result = new Solution();
result.setModel(model);
private Instance findInstance(Implementation implementation, String compName)
{
for (ComponentRequirement componentRequirement : implementation.getComponentRequirements())
{
for (Instance instance : componentRequirement.getInstances())
{
if (instance.getName().toString().equals(compName))
{
return instance;
}
}
}
return null;
}
// top level
for (ECompMapping eCompMap : eSolution.getCompMappings())
private Resource findResource(String nodeName)
{
for (Resource r : model.getHardwareModel().getResources())
{
if (r.getName().toString().equals(nodeName))
{
Assignment assignment = new Assignment();
assignment.setRequest(findRequest(eCompMap.getRequName()));
assignment.setTopLevel(true);
result.addAssignment(assignment);
return r;
}
}
return null;
}
return result;
private Implementation findImplementation(Component comp, String implName)
{
for (Implementation impl : comp.getImplementations())
{
if (impl.getName().toString().equals(implName))
{
return impl;
}
}
return null;
}
private Request findRequest(String requName)
......
......@@ -27,7 +27,7 @@ public class EMFeRSolverTest {
* tests the simple solver with one very simple use case
*/
@Test
public void testSimpleSolver() throws SolvingException {
public void testEmferSolver() throws SolvingException {
int tlc = 1;
int iac = 2;
int isd = 0;
......@@ -38,7 +38,7 @@ public class EMFeRSolverTest {
int mod = 3;
double res = 1.5d;
int nfp = 0;
int req = 1;
int req = 3;
int cpu = 1;
int seed = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment