mirror of
https://github.com/Echtzeitsysteme/gips-examples.git
synced 2024-05-20 20:00:43 +00:00
Enforces our code style
This commit is contained in:
parent
4a96e7870b
commit
f0dc49684c
|
@ -18,40 +18,40 @@ import java.util.Random;
|
|||
* 3. deviation
|
||||
*/
|
||||
public record GenParameter(GenDistribution dist, double[] parameters) {
|
||||
public GenParameter(GenDistribution dist, double ... parameters) {
|
||||
public GenParameter(GenDistribution dist, double... parameters) {
|
||||
this.dist = dist;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
|
||||
double getParam(final Random rnd) {
|
||||
return switch(dist) {
|
||||
case CONST -> {
|
||||
if(parameters.length != 1)
|
||||
throw new IllegalArgumentException("Expected parameters size 1, got " + parameters.length + ".");
|
||||
|
||||
yield parameters[0];
|
||||
}
|
||||
case EXP -> {
|
||||
if(parameters.length != 1)
|
||||
throw new IllegalArgumentException("Expected parameters size 1, got " + parameters.length + ".");
|
||||
|
||||
yield Math.log(1 - rnd.nextDouble() / -parameters[0]);
|
||||
}
|
||||
case N -> {
|
||||
if(parameters.length != 2)
|
||||
throw new IllegalArgumentException("Expected parameters size 2, got " + parameters.length + ".");
|
||||
|
||||
yield rnd.nextGaussian(parameters[0], parameters[1]);
|
||||
}
|
||||
case UNI -> {
|
||||
if(parameters.length != 2)
|
||||
throw new IllegalArgumentException("Expected parameters size 2, got " + parameters.length + ".");
|
||||
|
||||
yield rnd.nextDouble(parameters[0], parameters[1]);
|
||||
}
|
||||
default -> {
|
||||
throw new IllegalArgumentException("Unknown enumerator.");
|
||||
}
|
||||
return switch (dist) {
|
||||
case CONST -> {
|
||||
if (parameters.length != 1)
|
||||
throw new IllegalArgumentException("Expected parameters size 1, got " + parameters.length + ".");
|
||||
|
||||
yield parameters[0];
|
||||
}
|
||||
case EXP -> {
|
||||
if (parameters.length != 1)
|
||||
throw new IllegalArgumentException("Expected parameters size 1, got " + parameters.length + ".");
|
||||
|
||||
yield Math.log(1 - rnd.nextDouble() / -parameters[0]);
|
||||
}
|
||||
case N -> {
|
||||
if (parameters.length != 2)
|
||||
throw new IllegalArgumentException("Expected parameters size 2, got " + parameters.length + ".");
|
||||
|
||||
yield rnd.nextGaussian(parameters[0], parameters[1]);
|
||||
}
|
||||
case UNI -> {
|
||||
if (parameters.length != 2)
|
||||
throw new IllegalArgumentException("Expected parameters size 2, got " + parameters.length + ".");
|
||||
|
||||
yield rnd.nextDouble(parameters[0], parameters[1]);
|
||||
}
|
||||
default -> {
|
||||
throw new IllegalArgumentException("Unknown enumerator.");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,15 +21,15 @@ import LectureStudioModelB.LectureStudioServer;
|
|||
import LectureStudioModelB.Network;
|
||||
|
||||
public class LSGenerator {
|
||||
|
||||
|
||||
public static final DecimalFormat df = new DecimalFormat("0.00");
|
||||
|
||||
public static String projectFolder = System.getProperty("user.dir");
|
||||
public static String instancesFolder = projectFolder + "/../org.emoflon.gips.gipsl.examples.lsp2p/instances/";
|
||||
|
||||
|
||||
protected LectureStudioModelBFactory factory = LectureStudioModelBFactory.eINSTANCE;
|
||||
protected Random rnd;
|
||||
|
||||
|
||||
public static void initFileSystem() {
|
||||
File iF = new File(instancesFolder);
|
||||
if (!iF.exists()) {
|
||||
|
@ -41,7 +41,7 @@ public class LSGenerator {
|
|||
initFileSystem();
|
||||
simpleInitialBatch(10);
|
||||
}
|
||||
|
||||
|
||||
public static Network simpleInitialBatch(int numOfConfigs) {
|
||||
LSGenerator gen = new LSGenerator("FunSeed123".hashCode());
|
||||
double fileSize = 10;
|
||||
|
@ -49,15 +49,12 @@ public class LSGenerator {
|
|||
int clients = 5;
|
||||
double clientsUp = 50;
|
||||
double clientsDown = 150;
|
||||
|
||||
Network net = gen.generateInitial(
|
||||
numOfConfigs,
|
||||
new GenParameter(GenDistribution.CONST, fileSize),
|
||||
new GenParameter(GenDistribution.CONST, lsBW),
|
||||
new GenParameter(GenDistribution.CONST, clients),
|
||||
|
||||
Network net = gen.generateInitial(numOfConfigs, new GenParameter(GenDistribution.CONST, fileSize),
|
||||
new GenParameter(GenDistribution.CONST, lsBW), new GenParameter(GenDistribution.CONST, clients),
|
||||
new GenParameter(GenDistribution.UNI, 10, clientsUp),
|
||||
new GenParameter(GenDistribution.CONST, clientsDown));
|
||||
|
||||
|
||||
StringBuilder fileName = new StringBuilder();
|
||||
// fileName.append("/LSBW@");
|
||||
// fileName.append(df.format(lsBW).replace(",", "-"));
|
||||
|
@ -81,7 +78,7 @@ public class LSGenerator {
|
|||
|
||||
return net;
|
||||
}
|
||||
|
||||
|
||||
public static void save(Network model, String path) throws IOException {
|
||||
URI uri = URI.createFileURI(path);
|
||||
ResourceSet rs = new ResourceSetImpl();
|
||||
|
@ -92,26 +89,27 @@ public class LSGenerator {
|
|||
r.save(null);
|
||||
r.unload();
|
||||
}
|
||||
|
||||
|
||||
public LSGenerator(long seed) {
|
||||
rnd = new Random(seed);
|
||||
}
|
||||
|
||||
public Network generateInitial(int numOfConfigs, GenParameter data, GenParameter lsBwUp, GenParameter nodes, GenParameter nodeBwUp, GenParameter nodeBwDown) {
|
||||
|
||||
public Network generateInitial(int numOfConfigs, GenParameter data, GenParameter lsBwUp, GenParameter nodes,
|
||||
GenParameter nodeBwUp, GenParameter nodeBwDown) {
|
||||
int id = 0;
|
||||
Network net = factory.createNetwork();
|
||||
net.setTime(0);
|
||||
|
||||
|
||||
LectureStudioServer ls = factory.createLectureStudioServer();
|
||||
ls.setData(data.getParam(rnd));
|
||||
ls.setId(""+id++);
|
||||
ls.setId("" + id++);
|
||||
ls.setTxBW(lsBwUp.getParam(rnd));
|
||||
ls.setMinTxBW(ls.getTxBW()/20.0);
|
||||
ls.setMinTxBW(ls.getTxBW() / 20.0);
|
||||
// Rx is actually not needed.
|
||||
ls.setRxBW(lsBwUp.getParam(rnd));
|
||||
ls.setInvTxBW(1.0/ls.getTxBW());
|
||||
ls.setInvTxBW(1.0 / ls.getTxBW());
|
||||
// Rx is actually not needed.
|
||||
ls.setInvRxBW(1.0/ls.getRxBW());
|
||||
ls.setInvRxBW(1.0 / ls.getRxBW());
|
||||
// ls.setResidualTxBW(ls.getTxBW());
|
||||
// // Same here.
|
||||
// ls.setResidualRxBW(ls.getRxBW());
|
||||
|
@ -123,33 +121,33 @@ public class LSGenerator {
|
|||
ls.setIsHasRoot(1);
|
||||
ls.setClients(0);
|
||||
net.getLectureStudioServer().add(ls);
|
||||
|
||||
|
||||
List<Configuration> configs = new LinkedList<>();
|
||||
for(int i = 0; i<numOfConfigs; i++) {
|
||||
for (int i = 0; i < numOfConfigs; i++) {
|
||||
Configuration config = factory.createConfiguration();
|
||||
config.setClients(i);
|
||||
config.setSlowDown(i);
|
||||
config.setBwSplit(1.0/i);
|
||||
config.setBwSplit(1.0 / i);
|
||||
configs.add(config);
|
||||
}
|
||||
net.getConfigurations().addAll(configs);
|
||||
|
||||
|
||||
List<Client> clients = new LinkedList<>();
|
||||
for(int i = (int)nodes.getParam(rnd); i>0; i--) {
|
||||
for (int i = (int) nodes.getParam(rnd); i > 0; i--) {
|
||||
Client client = factory.createClient();
|
||||
client.setData(ls.getData());
|
||||
client.setDepth(-1);
|
||||
client.setId(""+id++);
|
||||
client.setId("" + id++);
|
||||
client.setIsRelayClient(0);
|
||||
client.setTxBW(nodeBwUp.getParam(rnd));
|
||||
client.setMinTxBW(client.getTxBW()/2.0);
|
||||
client.setMinTxBW(client.getTxBW() / 2.0);
|
||||
client.setRxBW(nodeBwDown.getParam(rnd));
|
||||
// client.setResidualTxBW(client.getTxBW());
|
||||
// client.setResidualRxBW(client.getRxBW());
|
||||
// client.setAllocatedTxBW(0);
|
||||
// client.setAllocatedRxBW(0);
|
||||
client.setInvTxBW(1.0/client.getTxBW());
|
||||
client.setInvRxBW(1.0/client.getRxBW());
|
||||
client.setInvTxBW(1.0 / client.getTxBW());
|
||||
client.setInvRxBW(1.0 / client.getRxBW());
|
||||
client.setTransferTime(0);
|
||||
client.setIsRelayClient(0);
|
||||
client.setIsHasRoot(0);
|
||||
|
@ -158,29 +156,30 @@ public class LSGenerator {
|
|||
}
|
||||
ls.getWaitingClients().addAll(clients);
|
||||
net.setNextId(id);
|
||||
|
||||
|
||||
return net;
|
||||
}
|
||||
|
||||
public void insertRndClients(final LectureStudioServer ls, GenParameter nodes, GenParameter nodeBwUp, GenParameter nodeBwDown) {
|
||||
|
||||
public void insertRndClients(final LectureStudioServer ls, GenParameter nodes, GenParameter nodeBwUp,
|
||||
GenParameter nodeBwDown) {
|
||||
Network network = (Network) ls.eContainer();
|
||||
int id = network.getNextId();
|
||||
List<Client> clients = new LinkedList<>();
|
||||
for(int i = (int)nodes.getParam(rnd); i>0; i--) {
|
||||
for (int i = (int) nodes.getParam(rnd); i > 0; i--) {
|
||||
Client client = factory.createClient();
|
||||
client.setData(ls.getData());
|
||||
client.setDepth(-1);
|
||||
client.setId(""+id++);
|
||||
client.setId("" + id++);
|
||||
client.setIsRelayClient(0);
|
||||
client.setTxBW(nodeBwUp.getParam(rnd));
|
||||
client.setMinTxBW(client.getTxBW()/2.0);
|
||||
client.setMinTxBW(client.getTxBW() / 2.0);
|
||||
client.setRxBW(nodeBwDown.getParam(rnd));
|
||||
// client.setResidualTxBW(client.getTxBW());
|
||||
// client.setResidualRxBW(client.getRxBW());
|
||||
// client.setAllocatedTxBW(0);
|
||||
// client.setAllocatedRxBW(0);
|
||||
client.setInvTxBW(1.0/client.getTxBW());
|
||||
client.setInvRxBW(1.0/client.getRxBW());
|
||||
client.setInvTxBW(1.0 / client.getTxBW());
|
||||
client.setInvRxBW(1.0 / client.getRxBW());
|
||||
client.setTransferTime(0);
|
||||
client.setIsRelayClient(0);
|
||||
client.setIsHasRoot(0);
|
||||
|
@ -191,5 +190,3 @@ public class LSGenerator {
|
|||
network.setNextId(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ public class LSp2pBatch {
|
|||
ILPSolverOutput output = gipsApi.solveILPProblem();
|
||||
gipsApi.getRelay2Client().applyNonZeroMappings();
|
||||
gipsApi.getNode2Cfg().applyNonZeroMappings();
|
||||
|
||||
|
||||
String outputFile = instancesFolder + "/lsp2p_10clients_solved.xmi";
|
||||
try {
|
||||
gipsApi.saveResult(outputFile);
|
||||
|
|
|
@ -20,7 +20,7 @@ public class LSp2pIncremental {
|
|||
ILPSolverOutput output = gipsApi.solveILPProblem();
|
||||
gipsApi.getRelay2Client().applyNonZeroMappings();
|
||||
gipsApi.getNode2Cfg().applyNonZeroMappings();
|
||||
|
||||
|
||||
String outputFile = instancesFolder + "/lsp2p_10clients_solved.xmi";
|
||||
try {
|
||||
gipsApi.saveResult(outputFile);
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.emoflon.gips.gipsl.examples.lsp2p.run;
|
|||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
import org.emoflon.gips.core.ilp.ILPSolverOutput;
|
||||
|
@ -24,57 +23,52 @@ public class LSp2pIncremental {
|
|||
String projectFolder = System.getProperty("user.dir");
|
||||
String instancesFolder = projectFolder + "/instances";
|
||||
String file = instancesFolder + "/lsp2p_10clients.xmi";
|
||||
|
||||
|
||||
URI uri = URI.createFileURI(file);
|
||||
ResourceSet rs = prepareResource(uri);
|
||||
|
||||
|
||||
LSGenerator gen = new LSGenerator("FunSeed123".hashCode());
|
||||
Network net = gen.generateInitial(
|
||||
81,
|
||||
new GenParameter(GenDistribution.CONST, 1),
|
||||
new GenParameter(GenDistribution.CONST, 500),
|
||||
new GenParameter(GenDistribution.CONST, 8),
|
||||
new GenParameter(GenDistribution.UNI, 10, 100),
|
||||
new GenParameter(GenDistribution.CONST, 150));
|
||||
Network net = gen.generateInitial(81, new GenParameter(GenDistribution.CONST, 1),
|
||||
new GenParameter(GenDistribution.CONST, 500), new GenParameter(GenDistribution.CONST, 8),
|
||||
new GenParameter(GenDistribution.UNI, 10, 100), new GenParameter(GenDistribution.CONST, 150));
|
||||
rs.getResources().get(0).getContents().add(net);
|
||||
|
||||
|
||||
double tick = System.currentTimeMillis();
|
||||
|
||||
|
||||
gipsApi.init(rs);
|
||||
int i = 0;
|
||||
int limit = 10;
|
||||
ILPSolverOutput output = null;
|
||||
do {
|
||||
if(i != 0) {
|
||||
gen.insertRndClients(net.getLectureStudioServer().get(0),
|
||||
new GenParameter(GenDistribution.CONST, 8),
|
||||
new GenParameter(GenDistribution.UNI, 10, 100),
|
||||
new GenParameter(GenDistribution.CONST, 150));
|
||||
if (i != 0) {
|
||||
gen.insertRndClients(net.getLectureStudioServer().get(0), new GenParameter(GenDistribution.CONST, 8),
|
||||
new GenParameter(GenDistribution.UNI, 10, 100), new GenParameter(GenDistribution.CONST, 150));
|
||||
}
|
||||
|
||||
|
||||
do {
|
||||
gipsApi.buildILPProblem(true);
|
||||
output = gipsApi.solveILPProblem();
|
||||
|
||||
|
||||
gipsApi.getInitRoot2Client().applyNonZeroMappings(false);
|
||||
gipsApi.getRoot2Client().applyNonZeroMappings(false);
|
||||
gipsApi.getInitRelay2Client().applyNonZeroMappings(false);
|
||||
gipsApi.getRelay2Client().applyNonZeroMappings(false);
|
||||
gipsApi.getUpdateTT().applyNonZeroMappings(false);
|
||||
} while(gipsApi.getEMoflonAPI().ls2Waiting().hasMatches(true) && output != null && output.status() == ILPSolverStatus.OPTIMAL);
|
||||
|
||||
if(output == null || output.status() != ILPSolverStatus.OPTIMAL)
|
||||
} while (gipsApi.getEMoflonAPI().ls2Waiting().hasMatches(true) && output != null
|
||||
&& output.status() == ILPSolverStatus.OPTIMAL);
|
||||
|
||||
if (output == null || output.status() != ILPSolverStatus.OPTIMAL)
|
||||
break;
|
||||
|
||||
|
||||
i++;
|
||||
|
||||
} while(i<limit);
|
||||
|
||||
|
||||
} while (i < limit);
|
||||
|
||||
double tock = System.currentTimeMillis();
|
||||
|
||||
System.out.println("\n\n****** Took: " + (tock-tick) + "ms");
|
||||
|
||||
System.out.println("\n\n****** Took: " + (tock - tick) + "ms");
|
||||
System.out.println(output);
|
||||
|
||||
|
||||
String outputFile = instancesFolder + "/lsp2p_10clients_solved.xmi";
|
||||
try {
|
||||
gipsApi.saveResult(outputFile);
|
||||
|
@ -86,7 +80,7 @@ public class LSp2pIncremental {
|
|||
gipsApi.terminate();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
public static ResourceSet prepareResource(final URI uri) {
|
||||
ResourceSet rs = new ResourceSetImpl();
|
||||
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new SmartEMFResourceFactoryImpl("../"));
|
||||
|
|
Loading…
Reference in a new issue