forked from rap-lab-org/public_pymcpf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_example_cbss.py
94 lines (75 loc) · 2.06 KB
/
run_example_cbss.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
"""
Author: Zhongqiang (Richard) Ren
All Rights Reserved.
ABOUT: Entrypoint to the code.
Oeffentlich fuer: RSS22
"""
import context
import time
import numpy as np
import random
import cbss_msmp
import cbss_mcpf
import common as cm
def run_CBSS_MSMP():
"""
fully anonymous case, no assignment constraints.
"""
print("------run_CBSS_MSMP------")
ny = 10
nx = 10
grids = np.zeros((ny,nx))
# Image coordinate is used. Think about the matrix as a 2d image with the origin at the upper left corner.
# Row index is y and column index is x.
# For example, in the matrix, grids[3,4] means the vertex with coordinate y=3,x=4 (row index=3, col index=4).
grids[5,3:7] = 1 # obstacles
# The following are vertex IDs.
# For a vertex v with (x,y) coordinate in a grid of size (Lx,Ly), the ID of v is y*Lx+x.
starts = [11,22,33,88,99]
targets = [40,38,27,66,72,81,83]
dests = [19,28,37,46,69]
configs = dict()
configs["problem_str"] = "msmp"
configs["tsp_exe"] = "./pytspbridge/tsp_solver/LKH-2.0.9/LKH"
configs["time_limit"] = 60
configs["eps"] = 0.0
res_dict = cbss_msmp.RunCbssMSMP(grids, starts, targets, dests, configs)
print(res_dict)
return
def run_CBSS_MCPF():
"""
With assignment constraints.
"""
print("------run_CBSS_MCPF------")
ny = 10
nx = 10
grids = np.zeros((ny,nx))
grids[5,3:7] = 1 # obstacles
starts = [11,22,33,88,99]
targets = [72,81,83,40,38,27,66]
dests = [46,69,19,28,37]
ac_dict = dict()
ri = 0
for k in targets:
ac_dict[k] = set([ri,ri+1])
ri += 1
if ri >= len(starts)-1:
break
ri = 0
for k in dests:
ac_dict[k] = set([ri])
ri += 1
print("Assignment constraints : ", ac_dict)
configs = dict()
configs["problem_str"] = "msmp"
configs["tsp_exe"] = "./pytspbridge/tsp_solver/LKH-2.0.9/LKH"
configs["time_limit"] = 60
configs["eps"] = 0.0
res_dict = cbss_mcpf.RunCbssMCPF(grids, starts, targets, dests, ac_dict, configs)
print(res_dict)
return
if __name__ == '__main__':
print("begin of main")
run_CBSS_MSMP()
run_CBSS_MCPF()
print("end of main")