-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMolaDirectedGraph.cs
More file actions
69 lines (67 loc) · 1.83 KB
/
MolaDirectedGraph.cs
File metadata and controls
69 lines (67 loc) · 1.83 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
using System.Collections.Generic;
public class MolaDirectedGraph
{
List<List<DirectedEdge>> edges;
public MolaDirectedGraph(int nNodes)
{
InitList(nNodes);
}
private void InitList(int nNodes)
{
edges = new List<List<DirectedEdge>>(nNodes);
for (int i = 0; i < nNodes; i++)
{
edges.Add(new List<DirectedEdge>());
}
}
public void AddDirectedEdge(int node1,int node2,float weight=1)
{
List<DirectedEdge> nodeEdges = this.edges[node1];
nodeEdges.Add(new DirectedEdge(node1, node2, weight));
}
public void AddDoubleEdge(int node1, int node2, float weight1 = 1,float weight2=1)
{
AddDirectedEdge(node1, node2, weight1);
AddDirectedEdge(node2, node1, weight2);
}
public float SetDirectedWeight(int node1, int node2,float weight)
{
return 1;
}
public DirectedEdge GetDirectedEdge(int node1, int node2)
{
foreach (DirectedEdge edge in GetDirectedEdges(node1))
{
if (edge.n2 == node2) return edge;
}
return null;
}
public void SetWeight(int node1, int node2, float weight)
{
DirectedEdge edge = GetDirectedEdge(node1, node2);
if (edge != null)
{
edge.weight = weight;
}
}
public int NodesCount()
{
return edges.Count;
}
public List<DirectedEdge> GetDirectedEdges(int node)
{
return edges[node];
}
public class DirectedEdge
{
public DirectedEdge(int n1, int n2, float weight = 1)
{
this.n1 = n1;
this.n2 = n2;
this.weight = weight;
}
public int n1 = -1;
public int n2 = -1;
public float weight = 1;
}
}