Repository navigation
Expand file tree
/
Copy pathCSPInstance.java
More file actions
62 lines (55 loc) · 1.64 KB
/
Copy pathCSPInstance.java
File metadata and controls
62 lines (55 loc) · 1.64 KB
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
/**
* A struct-like class for a CSP instance. Variables are all public. Prepared for COSC 322
* @author yonggao
*
*/
public class CSPInstance {
public static final int NOT_VALID = -2;
public static final int IS_VALID = -1;
/**
* C[i][j] stores a reference variable for the binary Constraint between var i and var j.
* To make things simple, we will assume that the constraint is symmetric.
* Dimension = N * N
* i, j \in N
*/
Constraint[][] constraints = null;
/**
The i-th row domains[i][*] stores the status of the domain values of the
variable i:
(1). domains[i][j] = -2: value j is not a valid domain value for variable i:
either set by the problem definition or deleted
during pre-processing, e.g. pre-arc-processing.
(2). domains[i][j] = -1: value j is a valid domain value for variable i.
(3). domains[i][j] = t >= 0: value j is deleted during the
consistency propagation at level t of the search tree
dimension = N * K
i \in N
j \in K
*/
public int domains[][] = null;
int numOfVariables = 0; //num of variables
int numOfDomains = 0; //domain size
int numOfConstraints = 0; //number of constraints
/**
* Constructor
* @param constraints
* @param domains
*/
public CSPInstance(Constraint[][] constraints, int domains[][])
{
this.constraints = constraints;
this.domains = domains;
numOfVariables = constraints.length;
numOfDomains = domains[1].length;
for(int i = 0; i < numOfVariables; i++)
{
for(int j = i + 1; j < numOfVariables; j++)
{
if(constraints[i][j] != null)
{
numOfConstraints++;
}
}
}
}
}