This repository was archived by the owner on Aug 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.cs
More file actions
55 lines (46 loc) · 1.31 KB
/
Util.cs
File metadata and controls
55 lines (46 loc) · 1.31 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
public class Node
{
public string key { get; }
public int leftId { get; }
public int rightId { get; }
public int cost { get; }
public Node(string setKey, int setLeftId, int setRightId, int setCost)
{
key = setKey;
rightId = setRightId;
leftId = setLeftId;
cost = setCost;
}
}
public class Edge
{
public Node fromNode { get; }
public Node toNode { get; }
public int cost { get; }
public Edge(Node setFromNode, Node setToNode, int setCost)
{
fromNode = setFromNode;
toNode = setToNode;
cost = setCost;
}
}
public class Lattice
{
public List<Node> nodes { get; } = new();
public List<Edge> edges { get; } = new();
public Dictionary<Node, List<Edge>> outEdges { get; } = new();
public Dictionary<Node, List<Edge>> inEdges { get; } = new();
public void AddEdge(Node from, Node to, int cost)
{
var edge = new Edge(from, to, cost);
edges.Add(edge);
if (!outEdges.ContainsKey(from))
outEdges[from] = new List<Edge>();
outEdges[from].Add(edge);
if(!inEdges.ContainsKey(to))
inEdges[to] = new List<Edge>();
inEdges[to].Add(edge);
if (!nodes.Contains(from)) nodes.Add(from);
if (!nodes.Contains(to)) nodes.Add(to);
}
}