-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
53 lines (43 loc) · 1.8 KB
/
main.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
from tool import inputEdge, inputNode, BestStation
from agent import PlannerAgent, CustomerAgent, RouteAgent
from agent import constants
from math import atan2
calculate_times = 30
edgeFile = r'.\data\input_distance-time.txt'
nodeFile = r'.\data\input_node.xlsx'
initFile = r'.\data\station_choice0.txt'
outputFile = r'.\data\solution6101.txt'
def sort_nodes(nodes, x0, y0):
nodes.sort(key = lambda nd : atan2(nd.y - y0, nd.x - x0))
def calculate():
edges = inputEdge.initEdges(edgeFile)
centNodes, custNodes, statNodes = inputNode.initNodes(nodeFile)
chargeChoice = BestStation.get_best_station(len(centNodes) + len(custNodes), initFile)
sort_nodes(custNodes, centNodes[0].x, centNodes[0].y)
custAgents = [CustomerAgent(nd) for nd in custNodes]
newRoute = lambda vehi_info: RouteAgent(edges, centNodes[0], chargeChoice, vehi_info)
planner = PlannerAgent(centNodes[0], custAgents, newRoute)
planner.get_initial_solution()
#planner.check_solution()
#planner.print_solution(r'.\solution.txt')
for i in range(calculate_times):
planner.init_movePool()
planner.p_best_move_selection()
if (i % 3 == 0):
planner.p_route_optimization()
planner.check_solution()
planner.find_charging_station()
planner.check_solution()
planner.print_solution(outputFile)
def init_best_station():
edges = inputEdge.initEdges(edgeFile)
centNodes, custNodes, statNodes = inputNode.initNodes(nodeFile)
file = open(initFile, "w")
BestStation.init_best_station(edges, statNodes, \
len(centNodes) + len(custNodes), constants.charge_tm, file)
if __name__ == "__main__":
#s = input("init best station for customers(1)/do calculation(0)\n")
#if(int(s) == 1):
# init_best_station()
#else:
calculate()