diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/org.eclipse.viatra.dse/src/org/eclipse/viatra/dse/solutionstore/ModelSaverSolutionFoundHandler.java')
-rw-r--r-- | Solvers/VIATRA-Solver/org.eclipse.viatra.dse/src/org/eclipse/viatra/dse/solutionstore/ModelSaverSolutionFoundHandler.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/Solvers/VIATRA-Solver/org.eclipse.viatra.dse/src/org/eclipse/viatra/dse/solutionstore/ModelSaverSolutionFoundHandler.java b/Solvers/VIATRA-Solver/org.eclipse.viatra.dse/src/org/eclipse/viatra/dse/solutionstore/ModelSaverSolutionFoundHandler.java new file mode 100644 index 00000000..bbbe60de --- /dev/null +++ b/Solvers/VIATRA-Solver/org.eclipse.viatra.dse/src/org/eclipse/viatra/dse/solutionstore/ModelSaverSolutionFoundHandler.java | |||
@@ -0,0 +1,55 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2017, Andras Szabolcs Nagy and Daniel Varro | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | package org.eclipse.viatra.dse.solutionstore; | ||
10 | |||
11 | import java.util.HashSet; | ||
12 | |||
13 | import org.eclipse.emf.common.notify.Notifier; | ||
14 | import org.eclipse.viatra.dse.api.SolutionTrajectory; | ||
15 | import org.eclipse.viatra.dse.base.ThreadContext; | ||
16 | import org.eclipse.viatra.dse.util.EMFHelper; | ||
17 | |||
18 | public class ModelSaverSolutionFoundHandler implements ISolutionFoundHandler { | ||
19 | |||
20 | private HashSet<Object> savedSolutions = new HashSet<Object>(); | ||
21 | private ISolutionNameProvider solutionNameProvider; | ||
22 | |||
23 | public ModelSaverSolutionFoundHandler() { | ||
24 | solutionNameProvider = new IdBasedSolutionNameProvider("solution", "xmi"); | ||
25 | } | ||
26 | |||
27 | public ModelSaverSolutionFoundHandler(String extension) { | ||
28 | solutionNameProvider = new IdBasedSolutionNameProvider("solution", extension); | ||
29 | } | ||
30 | |||
31 | public ModelSaverSolutionFoundHandler(String prefix, String extension) { | ||
32 | solutionNameProvider = new IdBasedSolutionNameProvider(prefix, extension); | ||
33 | } | ||
34 | |||
35 | public ModelSaverSolutionFoundHandler(ISolutionNameProvider solutionNameProvider) { | ||
36 | this.solutionNameProvider = solutionNameProvider; | ||
37 | } | ||
38 | |||
39 | @Override | ||
40 | public void solutionTriedToSave(ThreadContext context, SolutionTrajectory trajectory) { | ||
41 | } | ||
42 | |||
43 | @Override | ||
44 | public void solutionFound(ThreadContext context, SolutionTrajectory trajectory) { | ||
45 | Object stateCode = trajectory.getSolution().getStateCode(); | ||
46 | |||
47 | if (savedSolutions.contains(stateCode)) { | ||
48 | return; | ||
49 | } | ||
50 | |||
51 | savedSolutions.add(stateCode); | ||
52 | Notifier clonedModel = EMFHelper.clone(context.getModel()); | ||
53 | EMFHelper.saveModel(clonedModel, solutionNameProvider.getName()); | ||
54 | } | ||
55 | } \ No newline at end of file | ||