-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphInstance.java
More file actions
132 lines (92 loc) · 3.15 KB
/
GraphInstance.java
File metadata and controls
132 lines (92 loc) · 3.15 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
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
import java.util.ArrayList;
//nir nicole, mmn13
//Graph instance genarator
public class GraphInstance {
private ArrayList<Point> listOfPoints;
private Boolean derivativePolynomIndicator = false;
private Boolean inSource=true; //OutSource ==false
private Boolean pointsConverted = false;
//default constructor
public GraphInstance() {
listOfPoints = new ArrayList<Point>(0);
}
//costume constructor (no convertion needed)
public GraphInstance(ArrayList<Point> points, boolean derivativeFlag) {
listOfPoints = new ArrayList<Point>(0);
for(int i = 0; i<points.size() ; i++)
listOfPoints.add(points.get(i));
setDerivativePolynomIndicator(derivativeFlag);
}
//costume constructor (with convertion)
public GraphInstance(ArrayList<Point> points, boolean derivativeFlag, double maxX, double maxY,int getWidth, int getHeight) {
listOfPoints = new ArrayList<Point>(0);
for(int i = 0; i<points.size() ; i++)
listOfPoints.add(points.get(i));
if(!pointsConverted)
{
convetOutsourcePoints(listOfPoints, maxX, maxY);
pointsConverted = true;
}
derivativePolynomIndicator = derivativeFlag;
}
//copy constructor
public GraphInstance(GraphInstance c) {
listOfPoints = new ArrayList<Point>(0);
for(int i = 0; i<c.listOfPoints.size() ; i++)
listOfPoints.add(c.listOfPoints.get(i));
derivativePolynomIndicator = c.derivativePolynomIndicator;
inSource= c.inSource; //OutSource ==false
pointsConverted = c.pointsConverted;
}
//getters and setters
//
public ArrayList<Point> getListOfPoints() {
return listOfPoints;
}
public Boolean getInSource() {
return inSource;
}
public Boolean getPointsConverted() {
return pointsConverted;
}
public void addPoint(Point p) {
this.listOfPoints.add(p);
}
public void setListOfPoints(ArrayList<Point> points, double maxX, double maxY,int getWidth, int getHeight) {
if(!pointsConverted)
{
if(!inSource)
convetOutsourcePoints(points, maxX, maxY);
pointsConverted = true;
}
}
public void setInSource(Boolean flag) {
inSource = flag ;
}
public void setPointsConverted(Boolean flag) {
pointsConverted = flag ;
}
public Boolean getDerivativePolynomIndicator() {
return derivativePolynomIndicator;
}
public void setDerivativePolynomIndicator(Boolean flag) {
derivativePolynomIndicator = flag;
}
//convert outsource ratio to actual point
public ArrayList<Point> convetOutsourcePoints(ArrayList<Point> points, double maxX, double maxY) {
for(int j=0; j<points.size();j++)
{
points.get(j).setX((double)(points.get(j).getX() + maxX)/ (2*maxX )); // 0.5 + (this.points.get(j).getY())/(2*maxY)
points.get(j).setY( (double)(maxY - points.get(j).getY())/(2*maxY) ); // 0.5 - (this.points.get(j).getY())/(2*maxY)
}
return points;
}
//stringing the instance by formal presentation rules
public String toString()
{
String s = "List of points:\n";
for(int i=0; i<this.listOfPoints.size(); i++)
s+="point " + (i+1) + listOfPoints.get(i) + "\n";
return s; //"(x,y)"
}
}