-
Notifications
You must be signed in to change notification settings - Fork 2
/
ColorMatrix.java
138 lines (121 loc) · 2.49 KB
/
ColorMatrix.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
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Random;
public class ColorMatrix {
private boolean[][] colors;
private AdjMatrixGraph G;
//random coloring of graph G
public ColorMatrix(AdjMatrixGraph G) {
colors = new boolean[G.getVertices()][G.getVertices()];
this.G = G;
Random rand = new Random();
for(int i=0; i<G.getVertices(); i++)
{
for(int j=0; j<G.getVertices(); j++)
{
boolean color = rand.nextBoolean();
if(i<j)
{
colors[i][j] = color;
colors[j][i] = color;
}
}
}
}
//initializes a blank color matrix (for making new chromosomes)
public ColorMatrix(AdjMatrixGraph G, boolean blank)
{
colors = new boolean[G.getVertices()][G.getVertices()];
this.G = G;
for(int i=0; i<G.getVertices(); i++)
{
for(int j=0; j<G.getVertices(); j++)
{
boolean color = false;
if(i<j)
{
colors[i][j] = color;
colors[j][i] = color;
}
}
}
}
//load in a preformed coloring to the graph -- get this from a file
public ColorMatrix(AdjMatrixGraph G, boolean[][] coloring)
{
//this just copies the matrix over
colors = coloring;
this.G = G;
}
public boolean[][] getColorMatrix()
{
return this.colors;
}
public AdjMatrixGraph getGraph()
{
return this.G;
}
public boolean getColor(int x, int y)
{
return colors[x][y];
}
public void setColor(int x, int y, boolean color)
{
colors[x][y] = color;
colors[y][x] = color;
}
public boolean isRed(int x, int y)
{
//0 = red
if(!colors[x][y]) return true;
else return false;
}
public boolean isBlue(int x, int y)
{
//1 = blue
if(colors[x][y]) return true;
else return false;
}
public boolean[] makeChromosome()
{
for(int i=0; i<G.getVertices(); i++)
{
for(int j=0; j<G.getVertices(); j++)
{
}
}
return null;
}
public void printColoring()
{
//print
for(int i=0; i<G.getVertices(); i++)
{
for(int j=0; j<G.getVertices(); j++)
{
if(colors[i][j])
System.out.print(1+" ");
else
System.out.print(0+" ");
}
System.out.println();
}
}
public String getColoring()
{
//get
String coloring = "";
for(int i=0; i<G.getVertices(); i++)
{
for(int j=0; j<G.getVertices(); j++)
{
if(colors[i][j])
coloring+="1 ";
else
coloring+="0 ";
}
coloring+="\n";
}
return coloring;
}
}