-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopology.py
159 lines (132 loc) · 4.18 KB
/
topology.py
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#import modules
import sys, os
from math import *
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
#===========
# I/O PATHS
input_path = ''
#=========================
# MISCELLANEOUS FUNCTIONS
# manhattan distance
def one_norm(A,B):
return (abs(A.x-B.x)+abs(A.y-B.y))
#==========
# ENTITIES
class store:
def __init__(self,id, x, y, capacity, min_stock, refill_pc, exp_sale):
# identification
self.id=id
# cartesian location
self.x=x
self.y=y
# storage
self.capacity=capacity
self.curr_stock=capacity
self.min_stock=min_stock
self.refill_pc=refill_pc
# effective and missed sales
self.eff_sales = []
self.miss_sales = []
# data model: sales exp. distribution parameter
self.exp_sale=exp_sale
class warehouse:
def __init__(self,id, x, y, capacity, min_stock,refill_pc,parent):
# identification
self.id=id
# cartesian location
self.x=x
self.y=y
# storage
self.capacity=capacity
self.curr_stock=capacity
self.min_stock=min_stock
self.refill_pc=refill_pc
# production plant responsible for supply
self.parent=parent
class plant:
def __init__(self,id, x, y, capacity, prod_rate):
# identification
self.id=id
# cartesian location
self.x=x
self.y=y
# storage
self.capacity=capacity
self.curr_stock=capacity
# production rate
self.prod_rate=prod_rate
class truck:
def __init__(self,id, capacity, actual_load, route, on_hold, base_cost, cost_per_mile, max_stores):
# identification
self.id=id
# capacity
self.capacity=capacity
# number of products carried
self.actual_load=actual_load #WHY DO WE NEED THIS-SANGY
# route
self.route=route
# days truck is on hold
self.on_hold = on_hold
# daily cost of hiring a truck
self.base_cost = base_cost
# truck cost per mile traveled
self.cost_per_mile = cost_per_mile
# maximum number of stores
self.max_stores = max_stores
"""
>>>>>>>>> RESPONSE: to be able to calculate how much is spent on delivery per product
"""
#=========
# NETWORK
G=nx.Graph()
#=== NODES
# minimum percentage of capacity
min_percent = .0
# plants
P = [plant('P1',1.0,4.0,10000,100),
plant('P2',6.0,1.0,10000,100)]
# warehouses
W = [warehouse('W1',4.0,3.0,650,int(min_percent*650),100,P[0]),
warehouse('W2',9.0,2.0,650,int(min_percent*650),100,P[1])]
"""
REMOVED <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
"""
#T=[truck('T1',50,0,'',0,10,5)] #,truck('T2',50,0,'',0,10,20)]
"""
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
"""
# get store info (id,x,y,capacity,exp_sales_coefficient)
store_info = np.loadtxt(os.path.join(input_path,'store_info.csv'),delimiter=",",skiprows=1)
# stores
S=[]
for index in range(np.shape(store_info)[0]):#range(0,10):
S.append(store('S'+str(int(store_info[index,0])),
store_info[index,1],
store_info[index,2],
int(store_info[index,3]),
int(store_info[index,3]*min_percent),
100,
store_info[index,4]))
# add all nodes to graph
for entity in P+W+S:
G.add_node((entity.x,entity.y))
#=== EDGES
# path from plant to warehouse
G.add_edge((W[0].x,W[0].y),(W[0].parent.x,W[0].parent.y),length=one_norm(W[0].parent,W[0]))
G.add_edge((W[1].x,W[1].y),(W[1].parent.x,W[1].parent.y),length=one_norm(W[1].parent,W[1]))
# paths between stores and warehouses
W_n_S = W+S
for index in range(len(W_n_S)):
for neighbor_index in range(index+1,len(W_n_S)):
G.add_edge((W_n_S[index].x, W_n_S[index].y),(W_n_S[neighbor_index].x,W_n_S[neighbor_index].y),length=one_norm(W_n_S[index],W_n_S[neighbor_index]))
#=============
# OUTPUT INFO
# print graph info
print('The network contains:',G.number_of_nodes(),'nodes and ',G.number_of_edges(),' edges')
# plot the graph
# pos = nx.spring_layout(G)
# nx.draw(G, pos)
# nx.draw_networkx_edge_labels(G, pos)
#plt.show()