Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Preserve mappings after partial application #53

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
8 changes: 8 additions & 0 deletions gipsl.all.build.mappingpreservation/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src-gen"/>
<classpathentry kind="output" path="bin"/>
</classpath>
25 changes: 25 additions & 0 deletions gipsl.all.build.mappingpreservation/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>gipsl.all.build.mappingpreservation</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.emoflon.gips.gipsl.ui.gipsNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=21
17 changes: 17 additions & 0 deletions gipsl.all.build.mappingpreservation/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Manifest-Version: 1.0
Automatic-Module-Name: gipsl.all.build.mappingpreservation
Bundle-ManifestVersion: 2
Bundle-Name: gipsl.all.build.mappingpreservation
Bundle-Vendor: My Company
Bundle-Version: 1.0.0.qualifier
Export-Package: gipsl.all.build.mappingpreservation.connector
Bundle-SymbolicName: gipsl.all.build.mappingpreservation; singleton:=true
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-21
Require-Bundle: org.emoflon.ibex.common,
org.emoflon.ibex.gt,
org.emoflon.gips.core,
org.emoflon.ibex.gt.democles,
org.emoflon.ibex.gt.hipe,
gipsl.all.build.model;bundle-version="0.0.1",
test.suite.utils;bundle-version="1.0.0"
5 changes: 5 additions & 0 deletions gipsl.all.build.mappingpreservation/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source.. = src/,\
src-gen/
bin.includes = META-INF/,\
.,\
plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package "gipsl.all.build.mappingpreservation"
import "platform:/resource/gipsl.all.build.model/model/Model.ecore"

config {
solver := GUROBI [home:="fu", license:="bar"];
launchConfig := true [main := "TODO"];
timeLimit := true [value := 5.0];
randomSeed := true [value := 0];
presolve := true;
debugOutput := false;
}

condition vnodeNotMapped = forbid vnodeIsMapped
pattern vnodeIsMapped {
host: SubstrateNode

vnode: VirtualNode {
-host -> host
}
}

pattern vnodeNotMapped {
vnode: VirtualNode
}
when vnodeNotMapped

rule mapVnode {
root: Root {
-containers -> substrateContainer
-containers -> virtualContainer
}

substrateContainer: SubstrateContainer {
-substrateNodes -> snode
}

virtualContainer: VirtualContainer {
-virtualNodes -> vnode
}

snode: SubstrateResourceNode

vnode: VirtualResourceNode {
++ -host -> snode
}

# vnode.resourceDemand != 10
}

rule mapVnodeWith10ResDem {
root: Root {
-containers -> substrateContainer
-containers -> virtualContainer
}

substrateContainer: SubstrateContainer {
-substrateNodes -> snode
}

virtualContainer: VirtualContainer {
-virtualNodes -> vnode
}

snode: SubstrateResourceNode

vnode: VirtualResourceNode {
++ -host -> snode
}

# vnode.resourceDemand == 10
}

//
// GIPSL starts here!
//

mapping n2n with mapVnode;
mapping resDem with mapVnodeWith10ResDem;

// At most one mapping per virtual node is allowed
constraint -> class::VirtualNode {
mappings.n2n->filter(m | m.nodes().vnode == self)->count() <= 1
}

constraint -> class::VirtualNode {
mappings.resDem->filter(m | m.nodes().vnode == self)->count() <= 1
}

// Cost = 1 per mapped virtual node
objective maps -> mapping::n2n {
1
}

objective map10ResDem -> mapping::resDem {
1
}

global objective : max {
maps + map10ResDem
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package gipsl.all.build.mappingpreservation.connector;

import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.emoflon.gips.core.ilp.ILPSolverOutput;

import gipsl.all.build.mappingpreservation.api.gips.MappingpreservationGipsAPI;
import gipsl.all.build.mappingpreservation.api.gips.mapping.N2nMapping;
import gipsl.all.build.mappingpreservation.api.gips.mapping.ResDemMapping;
import gipsl.all.build.mappingpreservation.api.matches.MapVnodeMatch;
import gipsl.all.build.mappingpreservation.api.matches.MapVnodeWith10ResDemMatch;
import test.suite.gips.utils.AConnector;
import test.suite.gips.utils.GipsTestUtils;
import test.suite.gips.utils.GlobalTestConfig;

public class MappingPreservationConnector extends AConnector {

public MappingPreservationConnector(final String modelPath) {
api = new MappingpreservationGipsAPI();
api.init(GipsTestUtils.pathToAbsUri(modelPath));
GlobalTestConfig.overrideSolver(api);
}

@Override
public ILPSolverOutput run(final String outputPath) {
final ILPSolverOutput output = solve();
((MappingpreservationGipsAPI) api).getN2n().applyNonZeroMappings();
save(outputPath);
return output;
}

public ILPSolverOutput runWithNoApplication(final String outputPath) {
final ILPSolverOutput output = solve();
save(outputPath);
return output;
}

public List<Optional<MapVnodeMatch>> applyMappingWithVnodeName(final String vnodeName) {
final var mappings = ((MappingpreservationGipsAPI) api).getN2n().getNonZeroVariableMappings();
final var filtered = mappings.stream().filter(t -> {
return t.getMatch().getVnode().getName().equals(vnodeName);
}).toList();

// Check that only one mapping should be applied
if (filtered.size() != 1) {
throw new UnsupportedOperationException();
}

// Check if mapping to be applied has a value > 0
if (!(filtered.get(0).getValue() > 0)) {
throw new InternalError();
}

final var rule = ((MappingpreservationGipsAPI) api).getN2n().getGTRule();
return filtered.stream().map(m -> rule.apply(m.getMatch(), true)).collect(Collectors.toList());
}

public void save(final String path) {
super.save(path);
}

public Collection<N2nMapping> getN2nMappings() {
return ((MappingpreservationGipsAPI) api).getN2n().getMappings().values();
}

public Collection<ResDemMapping> getResDemMappings() {
return ((MappingpreservationGipsAPI) api).getResDem().getMappings().values();
}

public List<Optional<MapVnodeWith10ResDemMatch>> applyMappingWithVnode10Name(final String vnodeName) {
final var mappings = ((MappingpreservationGipsAPI) api).getResDem().getNonZeroVariableMappings();
final var filtered = mappings.stream().filter(t -> {
return t.getMatch().getVnode().getName().equals(vnodeName);
}).toList();

// Check that only one mapping should be applied
if (filtered.size() != 1) {
throw new UnsupportedOperationException();
}

// Check if mapping to be applied has a value > 0
if (!(filtered.get(0).getValue() > 0)) {
throw new InternalError();
}

final var rule = ((MappingpreservationGipsAPI) api).getResDem().getGTRule();
return filtered.stream().map(m -> rule.apply(m.getMatch(), true)).collect(Collectors.toList());
}

}
8 changes: 8 additions & 0 deletions gipsl.all.build.mappingpreservationb/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src-gen"/>
<classpathentry kind="output" path="bin"/>
</classpath>
25 changes: 25 additions & 0 deletions gipsl.all.build.mappingpreservationb/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>gipsl.all.build.mappingpreservationb</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.emoflon.gips.gipsl.ui.gipsNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=21
17 changes: 17 additions & 0 deletions gipsl.all.build.mappingpreservationb/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Manifest-Version: 1.0
Automatic-Module-Name: gipsl.all.build.mappingpreservationb
Bundle-ManifestVersion: 2
Bundle-Name: gipsl.all.build.mappingpreservationb
Bundle-Vendor: My Company
Bundle-Version: 1.0.0.qualifier
Export-Package: gipsl.all.build.mappingpreservationb.connector
Bundle-SymbolicName: gipsl.all.build.mappingpreservationb; singleton:=true
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-21
Require-Bundle: org.emoflon.ibex.common,
org.emoflon.ibex.gt,
org.emoflon.gips.core,
org.emoflon.ibex.gt.democles,
org.emoflon.ibex.gt.hipe,
gipsl.all.build.model,
test.suite.utils
5 changes: 5 additions & 0 deletions gipsl.all.build.mappingpreservationb/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source.. = src/,\
src-gen/
bin.includes = META-INF/,\
.,\
plugin.xml
Loading