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: Adds NOT == tests #27

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gipsl.all.build.notequal/.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-17"/>
<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.notequal/.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.notequal</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>
10 changes: 10 additions & 0 deletions gipsl.all.build.notequal/.settings/org.eclipse.jdt.core.prefs
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=17
org.eclipse.jdt.core.compiler.compliance=17
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=17
17 changes: 17 additions & 0 deletions gipsl.all.build.notequal/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.notequal
Bundle-ManifestVersion: 2
Bundle-Name: gipsl.all.build.notequal
Bundle-Vendor: My Company
Bundle-Version: 1.0.0.qualifier
Export-Package: gipsl.all.build.notequal.connector
Import-Package: test.suite.gips.utils
Bundle-SymbolicName: gipsl.all.build.notequal; singleton:=true
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-17
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"
5 changes: 5 additions & 0 deletions gipsl.all.build.notequal/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
61 changes: 61 additions & 0 deletions gipsl.all.build.notequal/src/gipsl/all/build/notequal/Model.gipsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package "gipsl.all.build.notequal"
import "platform:/resource/gipsl.all.build.model/model/Model.ecore"

config {
solver := GLPK [home:="fu", license:="bar"];
timeLimit := true [value := 10.0];
randomSeed := true [value := 0];
presolve := true;
debugOutput := true;
}

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

substrateContainer: SubstrateContainer {
-substrateNodes -> snode
}

virtualContainer: VirtualContainer {
-virtualNodes -> vnode
}

snode: SubstrateResourceNode {
++ -guests -> vnode
}

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

# vnode.resourceDemand <= snode.resourceAmountAvailable
# snode.resourceAmountAvailable >= 0
}

//
// GIPSL starts here!
//

mapping n2n with mapVnode;

// These two constraints should be equivalent

// NOT ...->count() == 1
constraint -> class::SubstrateResourceNode {
!mappings.n2n->filter(m | m.nodes().snode == self)->count() == 1
}
// ...->count() != 1
constraint -> class::SubstrateResourceNode {
mappings.n2n->filter(m | m.nodes().snode == self)->count() != 1
}

objective nObj -> mapping::n2n {
1
}

global objective : max {
nObj
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gipsl.all.build.notequal.connector;

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

import gipsl.all.build.notequal.api.gips.NotequalGipsAPI;
import test.suite.gips.utils.AConnector;
import test.suite.gips.utils.GipsTestUtils;
import test.suite.gips.utils.GlobalTestConfig;

public class NotEqualConnector extends AConnector {

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

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

}
1 change: 1 addition & 0 deletions test.suite.gips/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Import-Package: gips.generic.scheduling.connector,
gipsl.all.build.implicationstatic.connector,
gipsl.all.build.inheritedtypecontext.connector,
gipsl.all.build.nogt.connector,
gipsl.all.build.notequal.connector,
gipsl.all.build.objective.connector,
gipsl.all.build.objective.max.connector,
gipsl.all.build.objective.scaling.connector,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package test.suite.gipsl.all.build;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.emoflon.gips.core.ilp.ILPSolverOutput;
import org.emoflon.gips.core.ilp.ILPSolverStatus;
import org.junit.jupiter.api.Test;

import gipsl.all.build.notequal.connector.NotEqualConnector;

public class GipslAllBuildNotEqualTest extends AGipslAllBuildTest {

// Setup method

public void callableSetUp() {
gen.persistModel(MODEL_PATH);
con = new NotEqualConnector(MODEL_PATH);
}

// Actual tests

@Test
public void testMap1to1() {
gen.genSubstrateNode("s1", 1);
gen.genVirtualNode("v1", 1);
callableSetUp();

final ILPSolverOutput ret = con.run(OUTPUT_PATH);

assertEquals(ILPSolverStatus.OPTIMAL, ret.status());
// v1 must not be mapped because it is forbidden by the constraint
// (either more than one or 0 mappings per substrate node are allowed)
assertEquals(0, Math.abs(ret.objectiveValue()));
}

@Test
public void testMap2to1() {
gen.genSubstrateNode("s1", 1);
gen.genVirtualNode("v1", 1);
gen.genVirtualNode("v2", 1);
callableSetUp();

final ILPSolverOutput ret = con.run(OUTPUT_PATH);

assertEquals(ILPSolverStatus.OPTIMAL, ret.status());
// Both virtual nodes must be mapped because there is more than one mapping onto
// the same substrate node possible
assertEquals(2, Math.abs(ret.objectiveValue()));
}

}