Adds first draft of the objective test project

... and it does not compile, yet
This commit is contained in:
Maximilian Kratz 2022-05-17 14:09:36 +02:00
parent c0bd750d0b
commit e485cf5402
7 changed files with 184 additions and 0 deletions

View file

@ -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>

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>gipsl.all.build.objective</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.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
</projectDescription>

View file

@ -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

View file

@ -0,0 +1,15 @@
Manifest-Version: 1.0
Automatic-Module-Name: gipsl.all.build.objective
Bundle-ManifestVersion: 2
Bundle-Name: gipsl.all.build.objective
Bundle-Vendor: My Company
Bundle-Version: 1.0.0.qualifier
Bundle-SymbolicName: gipsl.all.build.objective; singleton:=true
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-16
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"

View file

@ -0,0 +1,5 @@
source.. = src/,\
src-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,49 @@
package gips.all.build.objective.connector;
import java.io.IOException;
import org.eclipse.emf.common.util.URI;
import org.emoflon.gips.core.ilp.ILPSolverOutput;
import gipsl.all.build.objective.api.gips.ObjectiveGipsAPI;
public class ObjectiveConnector {
final ObjectiveGipsAPI api;
public ObjectiveConnector(final String modelPath) {
if (modelPath == null || modelPath.isBlank()) {
throw new IllegalArgumentException("Model path is invalid!");
}
final URI absPath = URI.createFileURI(System.getProperty("user.dir") + "/" + modelPath);
api = new ObjectiveGipsAPI();
api.init(absPath);
}
public ILPSolverOutput run(final String outputPath) {
if (outputPath == null || outputPath.isBlank()) {
throw new IllegalArgumentException("Output path is invalid!");
}
final URI absPath = URI.createFileURI(System.getProperty("user.dir") + "/" + outputPath);
// Build the ILP problem (including updates)
api.buildILPProblem(true);
final ILPSolverOutput output = api.solveILPProblem();
System.out.println("Solver status: " + output.status());
System.out.println("Objective value: " + output.objectiveValue());
api.getA().applyNonZeroMappings();
try {
api.saveResult(absPath.toFileString());
} catch (final IOException e) {
e.printStackTrace();
}
return output;
}
}

View file

@ -0,0 +1,73 @@
import "platform:/resource/gipsl.all.build.model/model/Model.ecore"
config {
solver := GLPK [home:="fu", license:="bar"];
launchConfig := true [main := "TODO"];
timeLimit := true [value := 42.0];
randomSeed := true [value := 73];
presolve := true;
debugOutput := true;
}
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 {
++ -guests -> vnode
}
vnode: VirtualResourceNode {
++ -host -> snode
}
# vnode.resourceDemand <= snode.resourceAmountAvailable
# snode.resourceAmountAvailable >= 0
}
//
// GIPSL starts here!
//
mapping a with mapVnode;
constraint -> class::SubstrateResourceNode {
mappings.a->filter(m | m.nodes().snode == self)->sum(m | m.nodes().vnode.resourceDemand) <= self.resourceAmountAvailable
}
constraint -> pattern::vnodeNotMapped {
mappings.a->filter(m | m.nodes().vnode == self.nodes().vnode)->count() == 1
}
objective objA -> mapping::a {
1 + 2 + sin(3) + cos (4) + abs(-5) + -(6) + 7^3 + sqrt(8) + self.nodes().snode.resourceAmountTotal - 9 + 10/10
}
objective objB -> class::Root {
500
}
global objective : min {
2 * objA + 73 + 2 * objB
}