-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution.java
157 lines (131 loc) · 3.61 KB
/
Solution.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//******************************************************************************
//
// File: Solution.java
//
//******************************************************************************
/**
* Class Solution acts as a model to store the various parameters of the
* output from the Seesaw Search for solving the MAX-SAT problem.
*
* @author Harshad Paradkar
*
*/
public class Solution {
private float time; // Time taken for execution of Seesaw Search
private int noOfIterations; // Iterations to reach the returned solution
private int noOfSatisfiedClauses; // Satisfied clauses count
private int noOfVariables; // Variable count
private Clause[] clauses; // Array holding clauses in solution
/**
* Construct a Solution for the problem with the specified number of
* variables.
*
* @param noOfVariables Variable count for this Solution.
*/
public Solution(int noOfVariables) {
if(noOfVariables < 1) {
throw new IllegalArgumentException ("No of variables should be"
+ "non-zero positive integer.");
}else {
this.noOfVariables = noOfVariables;
}
}
/**
* Make a deep copy of the passed solution into this solution.
*
* @param solution The solution to be deep copied into this.
* @return The solution in which the deep copy was performed.
*/
public Solution copy(Solution solution){
this.noOfIterations = solution.noOfIterations;
this.noOfSatisfiedClauses = solution.noOfSatisfiedClauses;
this.time = solution.time;
try {
if(solution.clauses != null) {
this.clauses = Utilities.getDeepCopiedClauses(solution.clauses,
noOfVariables);
}
} catch (Exception e) {
e.printStackTrace();
}
return this;
}
/**
* @param solution
* @return
*/
public Solution update(Solution solution){
this.noOfIterations += solution.noOfIterations;
this.noOfSatisfiedClauses = solution.noOfSatisfiedClauses;
this.time += solution.time;
try {
if(solution.clauses != null) {
this.clauses = Utilities.getDeepCopiedClauses(solution.clauses,
noOfVariables);
}
} catch (Exception e) {
e.printStackTrace();
}
return this;
}
/**
* Create a deep copied clone of this solution, and return it.
*/
public Object clone(){
Solution solution = new Solution(this.noOfVariables);
solution.copy (this);
return solution;
}
/**
* @return The clauses in the solution.
*/
public Clause[] getClauses(){
return clauses;
}
/**
* @return The time taken for this instance of the search to provide
* this solution.
*/
public float getTime() {
return time;
}
/**
* @return The Satisfied clauses count in this solution.
*/
public int getNoOfSatisfiedClauses() {
return noOfSatisfiedClauses;
}
/**
* @return The value of max-tries to reach this solution.
*/
public int getNoOfIterations() {
return noOfIterations;
}
/**
* @param clauses Set the clauses in this solution to the given clauses.
*/
public void setClauses(Clause[] clauses) {
this.clauses = clauses;
}
/**
* @param time Set the time in this solution to the given time.
*/
public void setTime(float time) {
this.time = time;
}
/**
* @param noOfSatisfiedClauses Set the number of satisfied clauses in this
* solution to the given number of satisfied
* clauses.
*/
public void setNoOfSatisfiedClauses(int noOfSatisfiedClauses) {
this.noOfSatisfiedClauses = noOfSatisfiedClauses;
}
/**
* @param noOfIterations Set the number of iterations in this solution
* to the given number of iterations.
*/
public void setNoOfIterations(int noOfIterations) {
this.noOfIterations = noOfIterations;
}
}