-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcvrpGraph.py
More file actions
92 lines (63 loc) · 2.26 KB
/
cvrpGraph.py
File metadata and controls
92 lines (63 loc) · 2.26 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
# coding: utf-8
import numpy as np
class cvrpGraph:
def __init__(self):
self.name = None
self.filename = None
self.dimension = 0
self.adjMatrix = None # The graph is modeled with a matrix
self.capacity = None # The loading capacity setted by the cvrp files
self.comment = None
self.demand = []
self.depot = []
def setCapacity(self, capacity):
self.capacity = capacity
def getCapacity(self):
return self.capacity
def setComment(self, comment):
self.comment = comment
def getComment(self, comment):
self.comment = comment
def setName(self, name):
self.name = name
def getName(self):
return self.name
def setFileName(self, filename):
self.filename = filename
def getFileName(self):
return self.filename
def getValue(self, i, j):
return self.adjMatrix[i][j]
def setDimension(self, dimension):
self.dimension = dimension
self.adjMatrix = np.zeros(shape=(self.dimension, self.dimension))
def getDimension(self):
return self.dimension
def addEdge(self, vertex_from, vertex_to, weight):
self.adjMatrix[vertex_from][vertex_to] = weight
self.adjMatrix[vertex_to][vertex_from] = weight
def setDemand(self,demand):
self.demand = demand
def getDemand(self):
return self.demand
def setDepot(self,depot):
self.depot = depot
def getDepot(self):
return self.depot
def getArgMaxDistance(self):
return np.argmax(self.adjMatrix)
def getArgMaxNodeDistance(self,node):
return np.max(self.adjMatrix[node])
def getArgMinNodeDistance(self,node):
return np.argmin(self.adjMatrix[node])
def getMaxInterNodesDistance(self):
return np.max(self.adjMatrix[1:,1:])
def getMinInterNodesDistance(self):
indices = np.tril_indices(self.dimension-1,-1)
noDepotMat = self.adjMatrix[1:,1:]
return np.min(noDepotMat[indices])
def getNearestNeighbours(self,node, neighbours):
a = [(self.adjMatrix[node][n]) for n in neighbours]
return np.argmin(a),np.min(a)
def getTotalDemand(self):
return sum(self.demand)