-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathExampleChainGraph2.java
More file actions
executable file
·102 lines (82 loc) · 2.99 KB
/
ExampleChainGraph2.java
File metadata and controls
executable file
·102 lines (82 loc) · 2.99 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
// GraphTea Project: http://github.com/graphtheorysoftware/GraphTea
// Copyright (C) 2012 Graph Theory Software Foundation: http://GraphTheorySoftware.com
// Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
// Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
package graphtea.extensions.generators;
import graphtea.extensions.AlgorithmUtils;
import graphtea.graph.graph.Edge;
import graphtea.graph.graph.GPoint;
import graphtea.graph.graph.GraphModel;
import graphtea.graph.graph.Vertex;
import graphtea.platform.lang.CommandAttitude;
import graphtea.platform.parameter.Parameter;
import graphtea.platform.parameter.Parametrizable;
import graphtea.plugins.graphgenerator.GraphGenerator;
import graphtea.plugins.graphgenerator.core.PositionGenerators;
import graphtea.plugins.graphgenerator.core.SimpleGeneratorInterface;
import graphtea.plugins.graphgenerator.core.extension.GraphGeneratorExtension;
import java.util.ArrayList;
import java.util.List;
/**
* @author azin azadi
*/
@CommandAttitude(name = "generate_pn", abbreviation = "_g_pn")
public class ExampleChainGraph2 implements GraphGeneratorExtension, Parametrizable, SimpleGeneratorInterface {
@Parameter(name = "N")
public static Integer n = 9;
Vertex[] v;
public String getName() {
return "Chain Graph 2";
}
public String getDescription() {
return "Chain Graph 2";
}
public Vertex[] getVertices() {
Vertex[] ret = new Vertex[2*n];
for (int i = 0; i < 2*n; i++)
ret[i] = new Vertex();
v = ret;
return ret;
}
public Edge[] getEdges() {
List<Edge> ret = new ArrayList<>(); //new Edge[2 * n - 2 + n/3 + 2];
for (int i = 0; i < n - 1; i++) {
ret.add(new Edge(v[i], v[i + 1]));
}
for (int i = 0; i < n - 1; i++) {
ret.add(new Edge(v[i + n], v[i + 1 + n]));
}
for (int i = 0; i < n; i = i + 2) {
ret.add(new Edge(v[i], v[n + i]));
}
Edge[] ee = new Edge[ret.size()];
return ret.toArray(ee);
}
public GPoint[] getVertexPositions() {
GPoint[] p1 = PositionGenerators.line(5, 5, 10000, 10000, n);
GPoint[] p2 = PositionGenerators.line(1000, 5, 10000, 10000, n);
return AlgorithmUtils.concatArrays(p1,p2);
}
public String checkParameters() {
if (n < 0) return "n must be positive";
else
return null;
}
public GraphModel generateGraph() {
return GraphGenerator.getGraph(false, this);
}
/**
* generates a Path Graph with given parameters
*/
public static GraphModel generatePath(int n) {
ExampleChainGraph2.n = n;
return GraphGenerator.getGraph(false, new ExampleChainGraph2());
}
@Override
public String getCategory() {
return "Maxwell Examples";
}
public static void main(String[] args) {
new ExampleChainGraph2().generateGraph();
}
}