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