-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphAM.java
More file actions
107 lines (81 loc) · 2.42 KB
/
Copy pathGraphAM.java
File metadata and controls
107 lines (81 loc) · 2.42 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
import java.util.ArrayList;
public class GraphAM extends Graph{
public Double[] costs;
public int[][] adjacencyMatrix;
public int size; // number of vertex in the graph
public GraphAM(int size) {
this.size = size;
costs = new Double[size]; //Initialized with all 0s
adjacencyMatrix = new int[size][size];//Initialized with all 0s
}
public void addVertex(String name) {
// TODO Auto-generated method stub
name = name;
}
public void addEdge(String sourceName, String destinationName, double weight) {
int sourceIndex = findVertexIndex(sourceName);
int destinationIndex = findVertexIndex(destinationName);
adjacencyMatrix[sourceIndex][destinationIndex] = (int) weight;
}
public int findVertexIndex(String name) {
for (int i=0; i<size; i++) {
if (name.equals(name)) {
return i;
}
}
return -1;
}
public void print(){
for(int i = 0 ; i < size; i++){
for(int j = 0 ; j < size ; j++){
if(adjacencyMatrix[i][j] != 0){
System.out.println("name:"+(i+1)+",cost:"+costs[i]+" is connected with "+"name:"+(j+1)+",cost:"+costs[j] +" with edge-weight as "+adjacencyMatrix[i][j]);
}
}
}
}
@Override
public void addEdge(String snodename, String enodename) {
// TODO Auto-generated method stub
}
@Override
public ArrayList<Vertex> getAdjacentVertices(String parentVertex) {
// TODO Auto-generated method stub
return null;
}
@Override
public ArrayList<Vertex> getAdjacentVertices(int vIdx) {
// TODO Auto-generated method stub
return null;
}
@Override
public Vertex getVertex(int vIdx) {
// TODO Auto-generated method stub
return null;
}
@Override
public Vertex getVertex(String vertexName) {
// TODO Auto-generated method stub
return null;
}
@Override
public Vertex getedges(String name) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getNumberOfVertices() {
// TODO Auto-generated method stub
return 0;
}
@Override
public double getWeight(String fromVertexName, String toVertexName) {
// TODO Auto-generated method stub
return 0;
}
@Override
public double getWeight(int fromVertexIndex, int toVertexIndex) {
// TODO Auto-generated method stub
return 0;
}
}