Commit c61bb742 authored by Marta Różańska's avatar Marta Różańska
Browse files

changing the import in mcts solver, fixing imports

parent 9ee8ff1f
......@@ -17,10 +17,9 @@
<dependencies>
<dependency>
<groupId>org.ow2.paasage</groupId>
<groupId>eu.melodic</groupId>
<artifactId>cp-parser</artifactId>
<version>${melodic.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package eu.melodic.upperware.mcts_solver;
import cp_wrapper.utility_provider.implementations.UtilityProviderFromCDOFactory;
import cp_wrapper.utils.cp_variable.CpVariableCreator;
import cp_wrapper.utils.solution_result_notifier.SolutionResultNotifier;
import eu.melodic.cache.CacheService;
import eu.melodic.cache.NodeCandidates;
import eu.melodic.cache.impl.FilecacheService;
import eu.melodic.upperware.cp_wrapper.solution.CpSolution;
import eu.melodic.upperware.cp_wrapper.utility_provider.implementations.UtilityProviderFromCDOFactory;
import eu.melodic.upperware.cp_wrapper.utils.cp_variable.CpVariableCreator;
import eu.melodic.upperware.cp_wrapper.utils.solution_result_notifier.SolutionResultNotifier;
import eu.melodic.upperware.mcts_solver.solver.MCTSSolver;
import eu.melodic.upperware.mcts_solver.solver.mcts.cp_wrapper.MCTSWrapperFactoryImpl;
import eu.melodic.upperware.mcts_solver.solver.mcts.tree_impl.policy.AvailablePolicies;
import eu.melodic.upperware.penaltycalculator.PenaltyFunctionProperties;
import cp_wrapper.solution.CpSolution;
import eu.melodic.upperware.utilitygenerator.UtilityGeneratorApplication;
import eu.melodic.upperware.utilitygenerator.cdo.cp_model.DTO.VariableValueDTO;
import eu.melodic.upperware.utilitygenerator.properties.UtilityGeneratorProperties;
......@@ -20,7 +21,6 @@ import eu.paasage.upperware.metamodel.cp.ConstraintProblem;
import eu.paasage.upperware.metamodel.cp.CpVariableValue;
import eu.paasage.upperware.security.authapi.properties.MelodicSecurityProperties;
import eu.paasage.upperware.security.authapi.token.JWTService;
import io.github.cloudiator.rest.model.Runtime;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
......
package eu.melodic.upperware.mcts_solver.solver;
import cp_wrapper.solution.CpSolution;
import cp_wrapper.utils.runtime_limits.RuntimeLimit;
import eu.melodic.upperware.cp_wrapper.solution.CpSolution;
import eu.melodic.upperware.cp_wrapper.utils.runtime_limits.RuntimeLimit;
import eu.melodic.upperware.mcts_solver.solver.mcts.MCTSSingleTreeSolver;
import eu.melodic.upperware.mcts_solver.solver.mcts.cp_wrapper.MCTSWrapper;
import eu.melodic.upperware.mcts_solver.solver.mcts.cp_wrapper.MCTSWrapperFactory;
import eu.melodic.upperware.mcts_solver.solver.mcts.tree_impl.policy.AvailablePolicies;
import eu.melodic.upperware.mcts_solver.solver.utils.concurrency_utils.OneToManyChannel;
import eu.melodic.upperware.mcts_solver.solver.utils.concurrency_utils.SolutionBuffer;
......@@ -10,9 +12,6 @@ import eu.melodic.upperware.mcts_solver.solver.utils.concurrency_utils.messages.
import eu.melodic.upperware.mcts_solver.solver.utils.concurrency_utils.messages.Message;
import eu.melodic.upperware.mcts_solver.solver.utils.concurrency_utils.messages.TemperatureMessage;
import eu.melodic.upperware.mcts_solver.solver.utils.concurrency_utils.messages.UtilityMessage;
import eu.melodic.upperware.mcts_solver.solver.mcts.MCTSSingleTreeSolver;
import eu.melodic.upperware.mcts_solver.solver.mcts.cp_wrapper.MCTSWrapper;
import eu.melodic.upperware.mcts_solver.solver.mcts.cp_wrapper.MCTSWrapperFactory;
import eu.melodic.upperware.mcts_solver.solver.worker_thread.WorkerThread;
import lombok.extern.slf4j.Slf4j;
......@@ -38,7 +37,7 @@ public class MCTSSolver {
this.minTemperature = minTemperature;
this.maxTemperature = maxTemperature;
this.iterations = iterations;
this.messageChannel = new OneToManyChannel<>(numThreads);
this.messageChannel = new OneToManyChannel<>(numThreads);
this.policyType = policyType;
this.SAVE_TREE = saveTree;
}
......@@ -64,8 +63,8 @@ public class MCTSSolver {
private List<Thread> startWorkers(List<MCTSWrapper> mctsWrappers) {
return IntStream.range(0, numThreads).mapToObj(pid -> {
Thread thread = new Thread( () -> {
MCTSSingleTreeSolver mctsSingleTreeSolver = new MCTSSingleTreeSolver(minTemperature , 10, iterations, NODE_COUNT_LIMIT / numThreads, mctsWrappers.get(pid), policyType);
Thread thread = new Thread(() -> {
MCTSSingleTreeSolver mctsSingleTreeSolver = new MCTSSingleTreeSolver(minTemperature, 10, iterations, NODE_COUNT_LIMIT / numThreads, mctsWrappers.get(pid), policyType);
WorkerThread workerThread = new WorkerThread(pid, iterations, solutionBuffer, messageChannel, mctsSingleTreeSolver, SAVE_TREE);
workerThread.workerRun();
});
......@@ -87,7 +86,7 @@ public class MCTSSolver {
private void setTemperatures(List<UtilityMessage> results) {
double tempDiff = (maxTemperature - minTemperature) / numThreads;
IntStream.range(0, numThreads).forEach(thread -> messageChannel.coordinatorSend(new TemperatureMessage(minTemperature + thread*tempDiff), results.get(thread).getPid()));
IntStream.range(0, numThreads).forEach(thread -> messageChannel.coordinatorSend(new TemperatureMessage(minTemperature + thread * tempDiff), results.get(thread).getPid()));
}
private void stopWorkers() {
......
package eu.melodic.upperware.mcts_solver.solver.mcts;
import cp_wrapper.solution.CpSolution;
import eu.melodic.upperware.cp_wrapper.solution.CpSolution;
import eu.melodic.upperware.mcts_solver.solver.mcts.cp_wrapper.MCTSWrapper;
import eu.melodic.upperware.mcts_solver.solver.mcts.tree.*;
import eu.melodic.upperware.mcts_solver.solver.mcts.tree_impl.MemoryLimiterImpl;
......
package eu.melodic.upperware.mcts_solver.solver.mcts.cp_wrapper;
import cp_wrapper.CPWrapper;
import cp_wrapper.utils.numeric_value.NumericValueInterface;
import eu.melodic.cache.NodeCandidates;
import eu.melodic.upperware.cp_wrapper.CPWrapper;
import eu.melodic.upperware.cp_wrapper.utils.numeric_value.NumericValueInterface;
import eu.melodic.upperware.mcts_solver.solver.mcts.tree.Policy;
import eu.melodic.upperware.mcts_solver.solver.mcts.tree_impl.policy.AvailablePolicies;
import eu.melodic.upperware.mcts_solver.solver.mcts.tree_impl.policy.CheapestPolicyImpl;
import eu.melodic.upperware.mcts_solver.solver.mcts.tree.Policy;
import eu.melodic.upperware.mcts_solver.solver.mcts.tree_impl.policy.RandomPolicyImpl;
import eu.melodic.upperware.mcts_solver.solver.utils.NodeCandidatesProvider;
import eu.melodic.upperware.utilitygenerator.cdo.cp_model.DTO.VariableDTO;
import eu.melodic.upperware.utilitygenerator.cdo.cp_model.DTO.VariableValueDTO;
import eu.paasage.upperware.metamodel.cp.VariableType;
import lombok.extern.slf4j.Slf4j;
import java.util.Collection;
......@@ -19,7 +19,7 @@ import java.util.List;
import java.util.Random;
@Slf4j
public class MCTSWrapper{
public class MCTSWrapper {
private final Random random = new Random();
private CPWrapper cpWrapper;
private NodeCandidatesProvider nodeCandidatesProvider;
......@@ -95,7 +95,7 @@ public class MCTSWrapper{
}
public Policy createPolicy(AvailablePolicies policyType) {
switch(policyType) {
switch (policyType) {
case RANDOM_POLICY:
return new RandomPolicyImpl(this);
case CHEAPEST_POLICY:
......
package eu.melodic.upperware.mcts_solver.solver.mcts.cp_wrapper;
import cp_wrapper.CPWrapper;
import cp_wrapper.utility_provider.UtilityProviderFactory;
import eu.melodic.cache.NodeCandidates;
import eu.melodic.upperware.cp_wrapper.CPWrapper;
import eu.melodic.upperware.cp_wrapper.utility_provider.UtilityProviderFactory;
import eu.paasage.upperware.metamodel.cp.ConstraintProblem;
import lombok.AllArgsConstructor;
......
package eu.melodic.upperware.mcts_solver.solver.mcts.tree_impl.policy;
import cp_wrapper.utils.numeric_value.implementations.LongValue;
import eu.melodic.upperware.cp_wrapper.utils.numeric_value.implementations.LongValue;
import eu.melodic.upperware.mcts_solver.solver.mcts.cp_wrapper.MCTSWrapper;
import eu.melodic.upperware.mcts_solver.solver.mcts.tree.Path;
import eu.melodic.upperware.mcts_solver.solver.mcts.tree.Policy;
......
package eu.melodic.upperware.mcts_solver.solver.utils;
import cp_wrapper.CPWrapper;
import cp_wrapper.utils.domain_handler.DomainHandler;
import cp_wrapper.utils.numeric_value.implementations.IntegerValue;
import cp_wrapper.utils.numeric_value.implementations.LongValue;
import eu.melodic.cache.NodeCandidates;
import eu.melodic.upperware.cp_wrapper.CPWrapper;
import eu.melodic.upperware.cp_wrapper.utils.domain_handler.DomainHandler;
import eu.melodic.upperware.cp_wrapper.utils.numeric_value.implementations.IntegerValue;
import eu.melodic.upperware.cp_wrapper.utils.numeric_value.implementations.LongValue;
import eu.melodic.upperware.utilitygenerator.cdo.cp_model.DTO.VariableDTO;
import eu.paasage.upperware.metamodel.cp.Domain;
import eu.paasage.upperware.metamodel.cp.VariableType;
import io.github.cloudiator.rest.model.NodeCandidate;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.stream.Collectors;
public class NodeCandidatesProvider {
......@@ -34,18 +35,18 @@ public class NodeCandidatesProvider {
put(componentId, new HashMap<>());
}};
allCandidates.get().get(componentId).forEach((provider, nodes) -> {
if (providerIsInDomain(provider, cpWrapper.getVariableDomain(cpWrapper.getVariableIndexFromComponentAndType(componentId, VariableType.PROVIDER)))) {
candidates.get(componentId)
.put(provider, nodes.stream().filter(node -> candidateIsInDomain(node, cpWrapper, variables, componentId)).collect(Collectors.toList()));
}
if (providerIsInDomain(provider, cpWrapper.getVariableDomain(cpWrapper.getVariableIndexFromComponentAndType(componentId, VariableType.PROVIDER)))) {
candidates.get(componentId)
.put(provider, nodes.stream().filter(node -> candidateIsInDomain(node, cpWrapper, variables, componentId)).collect(Collectors.toList()));
}
});
return NodeCandidates.of(candidates);
}
private boolean candidateIsInDomain(NodeCandidate nodeCandidate, CPWrapper cpWrapper, Collection<VariableDTO> variables, String componentId) {
return variables.stream().filter(variable -> variable.getComponentId().equals(componentId))
.map(variable -> candidateIsInDomainOfVariable(variable.getType(), cpWrapper.getVariableDomain(cpWrapper.getVariableIndexFromComponentAndType(componentId, variable.getType())), nodeCandidate))
.reduce(Boolean::logicalAnd).orElse(true);
return variables.stream().filter(variable -> variable.getComponentId().equals(componentId))
.map(variable -> candidateIsInDomainOfVariable(variable.getType(), cpWrapper.getVariableDomain(cpWrapper.getVariableIndexFromComponentAndType(componentId, variable.getType())), nodeCandidate))
.reduce(Boolean::logicalAnd).orElse(true);
}
private boolean providerIsInDomain(int provider, Domain domain) {
......@@ -58,7 +59,7 @@ public class NodeCandidatesProvider {
} else if (isLocationType(type) && (nodeCandidate.getLocation() == null || nodeCandidate.getLocation().getGeoLocation() == null)) {
return false;
} else {
return DomainHandler.isInDomain(new LongValue(VariableExtractor.getVariableValue(type, nodeCandidate)),domain);
return DomainHandler.isInDomain(new LongValue(VariableExtractor.getVariableValue(type, nodeCandidate)), domain);
}
}
......
package eu.melodic.upperware.mcts_solver.solver.utils.concurrency_utils;
import cp_wrapper.solution.CpSolution;
import eu.melodic.upperware.cp_wrapper.solution.CpSolution;
import lombok.Getter;
public class SolutionBuffer {
......
package eu.melodic.upperware.mcts_solver.solver.worker_thread;
import cp_wrapper.solution.CpSolution;
import eu.melodic.upperware.cp_wrapper.solution.CpSolution;
import eu.melodic.upperware.mcts_solver.solver.mcts.MCTSSingleTreeSolver;
import eu.melodic.upperware.mcts_solver.solver.mcts.tree.Node;
import eu.melodic.upperware.mcts_solver.solver.utils.concurrency_utils.OneToManyChannel;
......@@ -89,5 +89,4 @@ public class WorkerThread {
}
}
import cp_wrapper.CPWrapper;
import cp_wrapper.utility_provider.UtilityProvider;
import eu.melodic.upperware.cp_wrapper.CPWrapper;
import eu.melodic.upperware.cp_wrapper.utility_provider.UtilityProvider;
import eu.melodic.upperware.mcts_solver.Methods;
import eu.melodic.upperware.mcts_solver.solver.mcts.MCTSSingleTreeSolver;
import eu.melodic.upperware.mcts_solver.solver.mcts.cp_wrapper.MCTSWrapper;
import eu.melodic.upperware.mcts_solver.solver.mcts.tree_impl.policy.AvailablePolicies;
import eu.paasage.upperware.metamodel.cp.*;
import eu.paasage.upperware.metamodel.cp.ConstraintProblem;
import org.junit.Test;
import java.util.Arrays;
......
package eu.melodic.upperware.mcts_solver;
import cp_wrapper.CPWrapper;
import cp_wrapper.solution.CpSolution;
import cp_wrapper.utility_provider.UtilityProvider;
import eu.melodic.upperware.cp_wrapper.CPWrapper;
import eu.melodic.upperware.cp_wrapper.solution.CpSolution;
import eu.melodic.upperware.cp_wrapper.utility_provider.UtilityProvider;
import eu.melodic.upperware.mcts_solver.solver.MCTSSolver;
import eu.melodic.upperware.mcts_solver.solver.mcts.cp_wrapper.MCTSWrapper;
import eu.melodic.upperware.mcts_solver.solver.mcts.cp_wrapper.MCTSWrapperFactory;
......@@ -12,53 +13,55 @@ import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.Map;
import static org.junit.Assert.assertEquals;
class MCTSSolverTest {
private final int NUM_THREADS = 5;
@Test
public void simpleCPTest() throws InterruptedException {
Map<String, Double> realBestSolution = new HashMap<String, Double>() {{
put("var1", 5.0);
put("var2", 2.5);
put("var3", 9.0);
}};
private final int NUM_THREADS = 5;
@Test
public void simpleCPTest() throws InterruptedException {
Map<String, Double> realBestSolution = new HashMap<String, Double>() {{
put("var1", 5.0);
put("var2", 2.5);
put("var3", 9.0);
}};
List<MCTSWrapper> mctsWrappers = IntStream.range(0, NUM_THREADS).mapToObj(thread -> {
List<MCTSWrapper> mctsWrappers = IntStream.range(0, NUM_THREADS).mapToObj(thread -> {
Map<ConstraintProblem, UtilityProvider> problem = Methods.prepareSimpleConstraintProblem();
CPWrapper cpWrapper = new CPWrapper();
cpWrapper.parse(problem.keySet().iterator().next(), problem.values().iterator().next());
return new MCTSWrapper(cpWrapper, null);
}).collect(Collectors.toList());
}).collect(Collectors.toList());
MCTSSolver mctsCoordinator = new MCTSSolver(NUM_THREADS, 0.001, 0.9, 100, AvailablePolicies.RANDOM_POLICY, false);
CpSolution solution = mctsCoordinator.solve(10, new MCTSWrapperFactory() {
private int index = -1;
@Override
public MCTSWrapper create() {
index++;
return mctsWrappers.get(index);
}
});
MCTSSolver mctsCoordinator = new MCTSSolver(NUM_THREADS, 0.001, 0.9, 100, AvailablePolicies.RANDOM_POLICY, false);
CpSolution solution = mctsCoordinator.solve(10, new MCTSWrapperFactory() {
private int index = -1;
solution.getSolution().forEach(variable -> {
assertEquals(java.util.Optional.of(variable.getValue().doubleValue()).orElse(0.0), realBestSolution.get(variable.getName()));
});
}
@Override
public MCTSWrapper create() {
index++;
return mctsWrappers.get(index);
}
});
solution.getSolution().forEach(variable -> {
assertEquals(java.util.Optional.of(variable.getValue().doubleValue()).orElse(0.0), realBestSolution.get(variable.getName()));
});
}
@Test
public void simpleCPTest2() throws InterruptedException {
Map<String, Double> realBestSolution = new HashMap<String, Double>() {{
put("var1", 4.0);
put("var2", 10.0);
put("var3", 9.0);
put("var4", 3.0);
put("var5", 12.5);
}};
put("var1", 4.0);
put("var2", 10.0);
put("var3", 9.0);
put("var4", 3.0);
put("var5", 12.5);
}};
List<MCTSWrapper> mctsWrappers = IntStream.range(0, NUM_THREADS).mapToObj(thread -> {
Map<ConstraintProblem, UtilityProvider> problem = Methods.prepareLessSimpleConstraintProblem();
......@@ -68,8 +71,9 @@ class MCTSSolverTest {
}).collect(Collectors.toList());
MCTSSolver mctsSolver = new MCTSSolver(NUM_THREADS, 0.001, 0.9, 100, AvailablePolicies.RANDOM_POLICY, false);
CpSolution solution = mctsSolver.solve(10, new MCTSWrapperFactory() {
CpSolution solution = mctsSolver.solve(10, new MCTSWrapperFactory() {
private int index = -1;
@Override
public MCTSWrapper create() {
index++;
......
package eu.melodic.upperware.mcts_solver;
import cp_wrapper.utility_provider.UtilityProvider;
import cp_wrapper.utils.test_utils.mockups.*;
import eu.melodic.upperware.cp_wrapper.utility_provider.UtilityProvider;
import eu.melodic.upperware.cp_wrapper.utils.test_utils.mockups.*;
import eu.melodic.upperware.utilitygenerator.cdo.cp_model.DTO.VariableValueDTO;
import eu.paasage.upperware.metamodel.cp.*;
import eu.paasage.upperware.metamodel.types.BasicTypeEnum;
......@@ -33,41 +33,50 @@ public class Methods {
List<String> variables = Arrays.asList("var1", "var2", "var3", "var4", "var5", "var6", "var7", "var8");
EList<CpVariable> vars = new BasicEList<>();
for (int i= 0; i < 3; i++) vars.add(new CpVariableImplMockup(variables.get(i), VariableType.CARDINALITY));
RangeDomainImpMockup dom1 = new RangeDomainImpMockup();
RangeDomainImpMockup dom3 = new RangeDomainImpMockup();
dom1.setFrom(1);dom3.setFrom(0);dom1.setTo(5);dom3.setTo(9);
for (int i = 0; i < 3; i++)
vars.add(new CpVariableImplMockup(variables.get(i), VariableType.CARDINALITY));
RangeDomainImpMockup dom1 = new RangeDomainImpMockup();
RangeDomainImpMockup dom3 = new RangeDomainImpMockup();
dom1.setFrom(1);
dom3.setFrom(0);
dom1.setTo(5);
dom3.setTo(9);
dom3.setType(BasicTypeEnum.INTEGER);
dom1.setType(BasicTypeEnum.INTEGER);
NumericListDomainImplMockup dom2 = new NumericListDomainImplMockup();
dom2.setValues(Arrays.asList(0.5, 1.5, 2.5));
dom2.setType(BasicTypeEnum.DOUBLE);
List<Domain> domains = Arrays.asList(new Domain[] {dom1, dom2, dom3});
for (int i = 0; i <3 ; i++ ){
List<Domain> domains = Arrays.asList(new Domain[]{dom1, dom2, dom3});
for (int i = 0; i < 3; i++) {
vars.get(i).setDomain(domains.get(i));
}
Constant c = new ConstantImplMockup(BasicTypeEnum.DOUBLE, new NumericValueUpperwareImplMockup(3));
EList<NumericExpression> exprs = new BasicEList<>();
exprs.add(vars.get(0)); exprs.add(vars.get(1));
exprs.add(vars.get(0));
exprs.add(vars.get(1));
NumericExpression times = new ComposedExpressionImplMockup(exprs, OperatorEnum.TIMES);
ComparisonExpressionMockup constraint1 = new ComparisonExpressionMockup();
constraint1.setExp1(vars.get(0));constraint1.setExp2(vars.get(2));
constraint1.setExp1(vars.get(0));
constraint1.setExp2(vars.get(2));
constraint1.setComparator(ComparatorEnum.LESS_THAN);
ComparisonExpressionMockup constraint3 = new ComparisonExpressionMockup();
constraint3.setExp1(times);constraint3.setExp2(vars.get(2));
constraint3.setExp1(times);
constraint3.setExp2(vars.get(2));
constraint3.setComparator(ComparatorEnum.GREATER_OR_EQUAL_TO);
exprs.add(vars.get(2));
ComparisonExpressionMockup constraint2 = new ComparisonExpressionMockup();
times = new ComposedExpressionImplMockup(exprs, OperatorEnum.TIMES);
constraint2.setExp1(times);constraint2.setExp2(c);
constraint2.setExp1(times);
constraint2.setExp2(c);
constraint2.setComparator(ComparatorEnum.GREATER_OR_EQUAL_TO);
ComparisonExpressionMockup constraint4 = new ComparisonExpressionMockup();
constraint4.setExp1(vars.get(2));constraint4.setExp2(vars.get(2));
constraint4.setExp1(vars.get(2));
constraint4.setExp2(vars.get(2));
constraint4.setComparator(ComparatorEnum.EQUAL_TO);
EList<Constant> consts = new BasicEList<>();
......@@ -79,7 +88,7 @@ public class Methods {
EList<ComparisonExpression> constraints = new BasicEList<>();
constraints.addAll(Arrays.asList(constraint1, constraint2, constraint3, constraint4));
ConstraintProblem cp = new ConstraintProblemMockup(consts,null, varsE, constraints );
ConstraintProblem cp = new ConstraintProblemMockup(consts, null, varsE, constraints);
return Collections.singletonMap(cp, result -> {
double sum = 0;
for (VariableValueDTO v : result) {
......@@ -116,13 +125,17 @@ public class Methods {
List<String> variables = Arrays.asList("var1", "var2", "var3", "var4", "var5", "var6", "var7", "var8", "var9", "var10", "var11", "var12");
EList<CpVariable> vars = new BasicEList<>();
for (int i= 0; i < 5; i++) vars.add(new CpVariableImplMockup(variables.get(i), VariableType.CARDINALITY));
RangeDomainImpMockup dom1 = new RangeDomainImpMockup();
RangeDomainImpMockup dom3 = new RangeDomainImpMockup();
RangeDomainImpMockup dom4 = new RangeDomainImpMockup();
dom1.setFrom(1); dom1.setTo(10);
dom3.setFrom(0); dom3.setTo(9);
dom4.setFrom(1); dom4.setTo(3);
for (int i = 0; i < 5; i++)
vars.add(new CpVariableImplMockup(variables.get(i), VariableType.CARDINALITY));
RangeDomainImpMockup dom1 = new RangeDomainImpMockup();
RangeDomainImpMockup dom3 = new RangeDomainImpMockup();
RangeDomainImpMockup dom4 = new RangeDomainImpMockup();
dom1.setFrom(1);
dom1.setTo(10);
dom3.setFrom(0);
dom3.setTo(9);
dom4.setFrom(1);
dom4.setTo(3);
dom1.setType(BasicTypeEnum.INTEGER);
dom3.setType(BasicTypeEnum.INTEGER);
dom4.setType(BasicTypeEnum.INTEGER);
......@@ -132,8 +145,8 @@ public class Methods {
dom5.setValues(Arrays.asList(0.5, 7.5, 12.5));
dom2.setType(BasicTypeEnum.DOUBLE);
dom5.setType(BasicTypeEnum.DOUBLE);
List<Domain> domains = Arrays.asList(new Domain[] {dom1, dom2, dom3, dom4, dom5});
for (int i = 0; i < 5 ; i++ ){
List<Domain> domains = Arrays.asList(new Domain[]{dom1, dom2, dom3, dom4, dom5});
for (int i = 0; i < 5; i++) {
vars.get(i).setDomain(domains.get(i));
}
......@@ -141,31 +154,38 @@ public class Methods {
Constant c2 = new ConstantImplMockup(BasicTypeEnum.DOUBLE, new NumericValueUpperwareImplMockup(6));
EList<NumericExpression> exprs = new BasicEList<>();
exprs.add(vars.get(0)); exprs.add(vars.get(1));
exprs.add(vars.get(0));
exprs.add(vars.get(1));
NumericExpression times = new ComposedExpressionImplMockup(exprs, OperatorEnum.TIMES);
ComparisonExpressionMockup constraint1 = new ComparisonExpressionMockup();
constraint1.setExp1(vars.get(0));constraint1.setExp2(vars.get(2));
constraint1.setExp1(vars.get(0));
constraint1.setExp2(vars.get(2));
constraint1.setComparator(ComparatorEnum.LESS_THAN);
ComparisonExpressionMockup constraint3 = new ComparisonExpressionMockup();
constraint3.setExp1(times);constraint3.setExp2(vars.get(2));
constraint3.setExp1(times);
constraint3.setExp2(vars.get(2));
constraint3.setComparator(ComparatorEnum.GREATER_OR_EQUAL_TO);
exprs.add(vars.get(2));
ComparisonExpressionMockup constraint2 = new ComparisonExpressionMockup();
times = new ComposedExpressionImplMockup(exprs, OperatorEnum.TIMES);
constraint2.setExp1(times);constraint2.setExp2(c);
constraint2.setExp1(times);
constraint2.setExp2(c);
constraint2.setComparator(ComparatorEnum.GREATER_OR_EQUAL_TO);
ComparisonExpressionMockup constraint4 = new ComparisonExpressionMockup();
constraint4.setExp1(vars.get(2));constraint4.setExp2(vars.get(2));
constraint4.setExp1(vars.get(2));
constraint4.setExp2(vars.get(2));
constraint4.setComparator(ComparatorEnum.EQUAL_TO);
EList<NumericExpression> exprs2 = new BasicEList<>();
EList<NumericExpression> exprs3 = new BasicEList<>();
exprs2.add(vars.get(0)); exprs2.add(vars.get(4));
exprs3.add(vars.get(1)); exprs3.add(c2);
exprs2.add(vars.get(0));
exprs2.add(vars.get(4));
exprs3.add(vars.get(1));
exprs3.add(c2);
ComparisonExpressionMockup constraint5 = new ComparisonExpressionMockup();
times = new ComposedExpressionImplMockup(exprs2, OperatorEnum.TIMES);
......@@ -183,7 +203,7 @@ public class Methods {
EList<ComparisonExpression> constraints = new BasicEList<>();
constraints.addAll(Arrays.asList(constraint1, constraint2, constraint3, constraint4, constraint5));
ConstraintProblem cp = new ConstraintProblemMockup(consts,null, varsE, constraints );
ConstraintProblem cp = new ConstraintProblemMockup(consts, null, varsE, constraints);
return Collections.singletonMap(cp, result -> {
double sum = 0;
for (VariableValueDTO v : result) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment