-
Notifications
You must be signed in to change notification settings - Fork 0
/
WipeOutR_FM_Model1.java
113 lines (89 loc) · 3.51 KB
/
WipeOutR_FM_Model1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* WipeOutR: Automated Redundancy Detection for Feature Models
*
* Copyright (c) 2022-2022 AIG team, Institute for Software Technology,
* Graz University of Technology, Austria
*
* Contact: http://ase.ist.tugraz.at/ASE/
*/
package at.tugraz.ist.ase.wipeoutr.testmodel;
import at.tugraz.ist.ase.cdrmodel.CDRModel;
import at.tugraz.ist.ase.cdrmodel.IChocoModel;
import at.tugraz.ist.ase.cdrmodel.test.csp.CSPModels;
import at.tugraz.ist.ase.common.IOUtils;
import at.tugraz.ist.ase.common.LoggerUtils;
import at.tugraz.ist.ase.kb.core.Constraint;
import at.tugraz.ist.ase.wipeoutr.model.IKBRedundancyDetectable;
import lombok.Cleanup;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.chocosolver.solver.Model;
import org.chocosolver.solver.variables.IntVar;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import static at.tugraz.ist.ase.csp2choco.CSP2ChocoTranslator.loadConstraints;
/**
* @author Viet-Man Le (vietman.le@ist.tugraz.at)
* Migrated to CA-CDR-V2
*/
@Slf4j
public class WipeOutR_FM_Model1 extends CDRModel implements IChocoModel, IKBRedundancyDetectable {
@Getter
private Model model;
@Getter
private List<Constraint> nonRedundantConstraints = new LinkedList<>();
public WipeOutR_FM_Model1() {
super("csp1.mzn");
}
@Override
public void initialize() throws IOException {
log.trace("{}Initializing CDRModel for {} >>>", LoggerUtils.tab(), getName());
LoggerUtils.indent();
// create the model
model = createModel();
// sets possibly faulty constraints to super class
List<Constraint> C = new ArrayList<>();
for (org.chocosolver.solver.constraints.Constraint c: model.getCstrs()) {
Constraint constraint = new Constraint(c.toString());
constraint.addChocoConstraint(c);
org.chocosolver.solver.constraints.Constraint opC = c.getOpposite(); // get negation of constraint
model.post(opC);
constraint.addNegChocoConstraint(opC);
C.add(constraint);
}
this.setPossiblyFaultyConstraints(C);
log.trace("{}Added constraints to the possibly faulty constraints [C={}]", LoggerUtils.tab(), C);
// expected results
nonRedundantConstraints.add(C.get(1));
nonRedundantConstraints.add(C.get(2));
model.unpost(model.getCstrs());
LoggerUtils.outdent();
log.debug("{}<<< Initialized CDRModel for {}", LoggerUtils.tab(), getName());
}
private Model createModel() throws IOException {
// create a model
Model model = new Model("csp1.mzn");
// Decision variables
IntVar x = model.intVar("x", -10, 10);
IntVar y = model.intVar("y", -10, 10);
log.trace("{}Created variables", LoggerUtils.tab());
ClassLoader classLoader = CSPModels.class.getClassLoader();
@Cleanup InputStream inputStream = IOUtils.getInputStream(classLoader, getName());
loadConstraints(inputStream, model);
log.trace("{}Created constraints", LoggerUtils.tab());
return model;
}
public Object clone() throws CloneNotSupportedException {
WipeOutR_FM_Model1 clone = (WipeOutR_FM_Model1) super.clone();
clone.nonRedundantConstraints = new LinkedList<>();
try {
clone.initialize();
} catch (IOException e) {
throw new CloneNotSupportedException(e.getMessage());
}
return clone;
}
}