|
1 |
| package org.sat4j.reader; |
|
2 |
| |
|
3 |
| import java.math.BigInteger; |
|
4 |
| |
|
5 |
| import org.sat4j.core.Vec; |
|
6 |
| import org.sat4j.core.VecInt; |
|
7 |
| import org.sat4j.specs.IVec; |
|
8 |
| import org.sat4j.specs.IVecInt; |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| public class ObjectiveFunction { |
|
19 |
| |
|
20 |
| |
|
21 |
| private final IVec<BigInteger> coeffs; |
|
22 |
| |
|
23 |
| private final IVecInt vars; |
|
24 |
| |
|
25 |
0
| public ObjectiveFunction(IVecInt vars, IVec<BigInteger> coeffs) {
|
|
26 |
0
| this.vars = new VecInt(vars.size());
|
|
27 |
0
| vars.copyTo(this.vars);
|
|
28 |
0
| this.coeffs = new Vec<BigInteger>(coeffs.size());
|
|
29 |
0
| coeffs.copyTo(this.coeffs);
|
|
30 |
| } |
|
31 |
| |
|
32 |
| |
|
33 |
0
| public BigInteger calculateDegree(int[] model) {
|
|
34 |
0
| BigInteger tempDegree = BigInteger.ZERO;
|
|
35 |
| |
|
36 |
0
| int indice;
|
|
37 |
0
| for (int i = 0; i < vars.size(); i++) {
|
|
38 |
0
| if (varInModel(vars.get(i), model))
|
|
39 |
0
| tempDegree = tempDegree.add(coeffs.get(i));
|
|
40 |
| } |
|
41 |
0
| return tempDegree;
|
|
42 |
| } |
|
43 |
| |
|
44 |
0
| private boolean varInModel(int var, int[] model) {
|
|
45 |
0
| for (int i = 0; i < model.length; i++)
|
|
46 |
0
| if (var == model[i])
|
|
47 |
0
| return true;
|
|
48 |
0
| return false;
|
|
49 |
| } |
|
50 |
| |
|
51 |
0
| public IVec<BigInteger> getCoeffs() {
|
|
52 |
0
| IVec<BigInteger> coefbis = new Vec<BigInteger>(coeffs.size());
|
|
53 |
0
| coeffs.copyTo(coefbis);
|
|
54 |
0
| return coefbis;
|
|
55 |
| } |
|
56 |
| |
|
57 |
0
| public IVecInt getVars() {
|
|
58 |
0
| IVecInt varbis = new VecInt(vars.size());
|
|
59 |
0
| vars.copyTo(varbis);
|
|
60 |
0
| return varbis;
|
|
61 |
| } |
|
62 |
| |
|
63 |
| } |