diff options
author | 2020-05-10 22:13:21 +0200 | |
---|---|---|
committer | 2020-05-10 22:13:21 +0200 | |
commit | 5a6eea9bd15597eab77bbcedb4b5116020f0a67d (patch) | |
tree | 6c86f7e5bd3d86fde29d3fee4fb4f912f35057bc /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java | |
parent | Add satellite case study (diff) | |
parent | Merge branch 'master' of https://github.com/viatra/VIATRA-Generator (diff) | |
download | VIATRA-Generator-5a6eea9bd15597eab77bbcedb4b5116020f0a67d.tar.gz VIATRA-Generator-5a6eea9bd15597eab77bbcedb4b5116020f0a67d.tar.zst VIATRA-Generator-5a6eea9bd15597eab77bbcedb4b5116020f0a67d.zip |
Merge branch 'master' of github.com:viatra/VIATRA-Generator
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java index 60f46033..18fe94e4 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java | |||
@@ -17,10 +17,12 @@ import java.util.Comparator; | |||
17 | import java.util.Iterator; | 17 | import java.util.Iterator; |
18 | import java.util.LinkedList; | 18 | import java.util.LinkedList; |
19 | import java.util.List; | 19 | import java.util.List; |
20 | import java.util.Map; | ||
20 | import java.util.PriorityQueue; | 21 | import java.util.PriorityQueue; |
21 | import java.util.Random; | 22 | import java.util.Random; |
22 | 23 | ||
23 | import org.apache.log4j.Logger; | 24 | import org.apache.log4j.Logger; |
25 | import org.eclipse.emf.ecore.EObject; | ||
24 | import org.eclipse.emf.ecore.util.EcoreUtil; | 26 | import org.eclipse.emf.ecore.util.EcoreUtil; |
25 | import org.eclipse.viatra.dse.api.strategy.interfaces.IStrategy; | 27 | import org.eclipse.viatra.dse.api.strategy.interfaces.IStrategy; |
26 | import org.eclipse.viatra.dse.base.ThreadContext; | 28 | import org.eclipse.viatra.dse.base.ThreadContext; |
@@ -38,6 +40,7 @@ import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem; | |||
38 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.InconsistencyResult; | 40 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.InconsistencyResult; |
39 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult; | 41 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult; |
40 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult; | 42 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult; |
43 | import hu.bme.mit.inf.dslreasoner.viatra2logic.NumericProblemSolver; | ||
41 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.ModelGenerationMethod; | 44 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.ModelGenerationMethod; |
42 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.PartialInterpretation2Logic; | 45 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.PartialInterpretation2Logic; |
43 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation; | 46 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation; |
@@ -80,12 +83,14 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
80 | private volatile boolean isInterrupted = false; | 83 | private volatile boolean isInterrupted = false; |
81 | private ModelResult modelResultByInternalSolver = null; | 84 | private ModelResult modelResultByInternalSolver = null; |
82 | private Random random = new Random(); | 85 | private Random random = new Random(); |
83 | private Collection<ViatraQueryMatcher<? extends IPatternMatch>> matchers; | 86 | //private Collection<ViatraQueryMatcher<? extends IPatternMatch>> matchers; |
84 | 87 | public ActivationSelector activationSelector = new EvenActivationSelector(random); | |
88 | public NumericSolver numericSolver = null; | ||
85 | // Statistics | 89 | // Statistics |
86 | private int numberOfStatecoderFail = 0; | 90 | private int numberOfStatecoderFail = 0; |
87 | private int numberOfPrintedModel = 0; | 91 | private int numberOfPrintedModel = 0; |
88 | private int numberOfSolverCalls = 0; | 92 | private int numberOfSolverCalls = 0; |
93 | |||
89 | 94 | ||
90 | public BestFirstStrategyForModelGeneration( | 95 | public BestFirstStrategyForModelGeneration( |
91 | ReasonerWorkspace workspace, | 96 | ReasonerWorkspace workspace, |
@@ -112,14 +117,14 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
112 | this.context = context; | 117 | this.context = context; |
113 | this.solutionStore = context.getGlobalContext().getSolutionStore(); | 118 | this.solutionStore = context.getGlobalContext().getSolutionStore(); |
114 | 119 | ||
115 | ViatraQueryEngine engine = context.getQueryEngine(); | 120 | // ViatraQueryEngine engine = context.getQueryEngine(); |
116 | // // TODO: visualisation | 121 | // // TODO: visualisation |
117 | matchers = new LinkedList<ViatraQueryMatcher<? extends IPatternMatch>>(); | 122 | // matchers = new LinkedList<ViatraQueryMatcher<? extends IPatternMatch>>(); |
118 | for(IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> p : this.method.getAllPatterns()) { | 123 | // for(IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> p : this.method.getAllPatterns()) { |
119 | //System.out.println(p.getSimpleName()); | 124 | // //System.out.println(p.getSimpleName()); |
120 | ViatraQueryMatcher<? extends IPatternMatch> matcher = p.getMatcher(engine); | 125 | // ViatraQueryMatcher<? extends IPatternMatch> matcher = p.getMatcher(engine); |
121 | matchers.add(matcher); | 126 | // matchers.add(matcher); |
122 | } | 127 | // } |
123 | 128 | ||
124 | this.solutionStoreWithCopy = new SolutionStoreWithCopy(); | 129 | this.solutionStoreWithCopy = new SolutionStoreWithCopy(); |
125 | this.solutionStoreWithDiversityDescriptor = new SolutionStoreWithDiversityDescriptor(configuration.diversityRequirement); | 130 | this.solutionStoreWithDiversityDescriptor = new SolutionStoreWithDiversityDescriptor(configuration.diversityRequirement); |
@@ -131,6 +136,8 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
131 | return objectiveComparatorHelper.compare(o2.fitness, o1.fitness); | 136 | return objectiveComparatorHelper.compare(o2.fitness, o1.fitness); |
132 | } | 137 | } |
133 | }; | 138 | }; |
139 | |||
140 | this.numericSolver = new NumericSolver(context, method, false); | ||
134 | 141 | ||
135 | trajectoiresToExplore = new PriorityQueue<TrajectoryWithFitness>(11, comparator); | 142 | trajectoiresToExplore = new PriorityQueue<TrajectoryWithFitness>(11, comparator); |
136 | } | 143 | } |
@@ -140,6 +147,9 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
140 | if (!context.checkGlobalConstraints()) { | 147 | if (!context.checkGlobalConstraints()) { |
141 | logger.info("Global contraint is not satisifed in the first state. Terminate."); | 148 | logger.info("Global contraint is not satisifed in the first state. Terminate."); |
142 | return; | 149 | return; |
150 | } else if(!numericSolver.isSatisfiable()) { | ||
151 | logger.info("Numeric contraints are not satisifed in the first state. Terminate."); | ||
152 | return; | ||
143 | } | 153 | } |
144 | if (configuration.searchSpaceConstraints.maxDepth == 0) { | 154 | if (configuration.searchSpaceConstraints.maxDepth == 0) { |
145 | logger.info("Maximal depth is reached in the initial solution. Terminate."); | 155 | logger.info("Maximal depth is reached in the initial solution. Terminate."); |
@@ -218,6 +228,9 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
218 | } else if (!context.checkGlobalConstraints()) { | 228 | } else if (!context.checkGlobalConstraints()) { |
219 | logger.debug("Global contraint is not satisifed."); | 229 | logger.debug("Global contraint is not satisifed."); |
220 | context.backtrack(); | 230 | context.backtrack(); |
231 | } else if (!numericSolver.isSatisfiable()) { | ||
232 | logger.debug("Numeric constraints are not satisifed."); | ||
233 | context.backtrack(); | ||
221 | } else { | 234 | } else { |
222 | final Fitness nextFitness = context.calculateFitness(); | 235 | final Fitness nextFitness = context.calculateFitness(); |
223 | checkForSolution(nextFitness); | 236 | checkForSolution(nextFitness); |
@@ -260,8 +273,7 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
260 | private List<Object> selectActivation() { | 273 | private List<Object> selectActivation() { |
261 | List<Object> activationIds; | 274 | List<Object> activationIds; |
262 | try { | 275 | try { |
263 | activationIds = new ArrayList<Object>(context.getUntraversedActivationIds()); | 276 | activationIds = this.activationSelector.randomizeActivationIDs(context.getUntraversedActivationIds()); |
264 | Collections.shuffle(activationIds); | ||
265 | } catch (NullPointerException e) { | 277 | } catch (NullPointerException e) { |
266 | numberOfStatecoderFail++; | 278 | numberOfStatecoderFail++; |
267 | activationIds = Collections.emptyList(); | 279 | activationIds = Collections.emptyList(); |
@@ -272,7 +284,8 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
272 | private void checkForSolution(final Fitness fittness) { | 284 | private void checkForSolution(final Fitness fittness) { |
273 | if (fittness.isSatisifiesHardObjectives()) { | 285 | if (fittness.isSatisifiesHardObjectives()) { |
274 | if (solutionStoreWithDiversityDescriptor.isDifferent(context)) { | 286 | if (solutionStoreWithDiversityDescriptor.isDifferent(context)) { |
275 | solutionStoreWithCopy.newSolution(context); | 287 | Map<EObject, EObject> trace = solutionStoreWithCopy.newSolution(context); |
288 | numericSolver.fillSolutionCopy(trace); | ||
276 | solutionStoreWithDiversityDescriptor.newSolution(context); | 289 | solutionStoreWithDiversityDescriptor.newSolution(context); |
277 | solutionStore.newSolution(context); | 290 | solutionStore.newSolution(context); |
278 | configuration.progressMonitor.workedModelFound(configuration.solutionScope.numberOfRequiredSolution); | 291 | configuration.progressMonitor.workedModelFound(configuration.solutionScope.numberOfRequiredSolution); |