Skip to content

Commit

Permalink
k camions
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulCombal committed Jul 3, 2019
1 parent 0df9d6d commit 98942e1
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 106 deletions.
29 changes: 29 additions & 0 deletions france
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
41 23
45 35
50 50
40 60
23 68
30 68
12 77
35 78
50 85
60 85
70 90
80 100
90 98
100 90
120 85
130 83
140 79
130 70
120 50
130 45
135 30
120 20
110 25
100 29
90 20
80 15
70 18
60 17
50 20
117 changes: 13 additions & 104 deletions report.csv
Original file line number Diff line number Diff line change
@@ -1,105 +1,14 @@
iterations,temps,distance,temperature
5000,1.3165578842163086,121.21824428467325,0.6721111959865606
10000,2.0787389278411865,97.8123419293458,0.4520495689035214
15000,2.6385505199432373,97.8123419293458,0.3038679424228721
20000,3.198474168777466,92.69046283557107,0.20426018026358692
25000,3.757519245147705,91.51600752694644,0.13730379357770844
30000,4.3160059452056885,91.51600752694644,9.23079397837336
35000,4.877627372741699,91.51600752694644,6.204944249678936
40000,5.4424684047698975,91.51600752694644,4.170966574687698
45000,6.003183126449585,91.51600752694644,2.8037257817525405
50000,6.564380168914795,91.51600752694644,1.8846658486714118
55000,7.1275928020477295,91.51600752694644,1.2668733098884215
60000,7.709557294845581,91.51600752694644,0.8515928616412607
65000,8.272701740264893,91.51600752694644,0.572441140197534
70000,8.83933424949646,91.51600752694644,0.3847952158254405
75000,9.403577327728271,88.48277680334007,0.25865953322476637
80000,9.963631629943848,88.48277680334007,0.17387106537833058
85000,10.529204845428467,88.48277680334007,0.11687621561400502
90000,11.091942071914673,88.48277680334007,7.857468750083974
95000,11.65352463722229,88.48277680334007,5.28179435616188
100000,12.218864679336548,88.48277680334007,3.5504247624892407
105000,12.778974294662476,88.48277680334007,2.3865972705640917
110000,13.341238498687744,88.48277680334007,1.6042718584101345
115000,13.90438961982727,88.48277680334007,1.0783923318065296
120000,14.464284658432007,88.48277680334007,0.7248958555263887
125000,15.026023149490356,88.48277680334007,0.4872753504089352
130000,15.591084957122803,88.46483730717296,0.32754673006611906
135000,16.15230083465576,88.46483730717296,0.2201770729567358
140000,16.71104145050049,88.46483730717296,0.14800313667002551
145000,17.276767253875732,88.46483730717296,9.95009990004999
150000,17.85395359992981,88.46483730717296,6.68846204380632
155000,18.41609501838684,88.46483730717296,4.4959874735743215
160000,18.976032257080078,86.96521115550244,3.022204989748841
165000,19.537293672561646,86.96521115550244,2.031527679680444
170000,20.10221004486084,86.96521115550244,1.3655939048829375
175000,20.682851552963257,86.96521115550244,0.9179528941228919
180000,21.248215913772583,86.96521115550244,0.6170483866511011
185000,21.812267303466797,86.96521115550244,0.41478022881831517
190000,22.361953496932983,86.96521115550244,0.2788154736977733
195000,22.92663311958313,86.96521115550244,0.18741989847198132
200000,23.475363969802856,86.96521115550244,0.12598374787951477
205000,24.040228366851807,86.96521115550244,8.469758853683537
210000,24.60388445854187,86.96521115550244,5.693376064774005
215000,25.165529012680054,86.96521115550244,3.827090189332175
220000,25.744653701782227,86.96521115550244,2.572571906483391
225000,26.315173149108887,86.96521115550244,1.7292841000913133
230000,26.881410598754883,86.96521115550244,1.1624256221146503
235000,27.452577829360962,86.96521115550244,0.7813830745782491
240000,28.007733821868896,86.96521115550244,0.5252460868220087
245000,28.578561544418335,86.96521115550244,0.3530706777475832
250000,29.141484260559082,86.96521115550244,0.2373342831345667
255000,29.709417819976807,86.96521115550244,0.15953622178522642
260000,30.27912664413452,86.96521115550244,0.10724032670439765
265000,30.829555988311768,86.96521115550244,7.209657768279316
270000,31.397671699523926,86.96521115550244,4.846335495759929
275000,31.963274002075195,82.41100956304545,3.2577091024763214
280000,32.53083896636963,82.41100956304545,2.1898336600184036
285000,33.09827971458435,82.41100956304545,1.472007262681753
290000,33.677080154418945,82.41100956304545,0.9894840055429684
295000,34.242270946502686,82.41100956304545,0.6651316349089464
300000,34.81053161621094,82.41100956304545,0.4471018119326612
305000,35.37738299369812,82.41100956304545,0.3005420577549795
310000,35.94760012626648,78.620704581794,0.2020245189549838
315000,36.55578374862671,78.620704581794,0.13580098094712142
320000,37.126696825027466,78.620704581794,9.129761418240957
325000,37.694416999816895,78.620704581794,6.137030113095166
330000,38.2617552280426,78.620704581794,4.12531465869275
335000,38.828099727630615,78.620704581794,2.77303854138044
340000,39.39502263069153,78.620704581794,1.864037870608908
345000,39.95929265022278,78.620704581794,1.2530071728950798
350000,40.52745842933655,78.620704581794,0.8422720375384076
355000,41.09604501724243,78.620704581794,0.5661756776539253
360000,41.66488742828369,78.620704581794,0.38058356882382527
365000,42.25156593322754,78.620704581794,0.2558284620400366
370000,42.81889510154724,78.620704581794,0.17196801793633615
375000,43.38672590255737,78.620704581794,0.1155969861880494
380000,43.95657014846802,78.620704581794,7.771467460721301
385000,44.52591562271118,78.620704581794,5.2239842471781746
390000,45.09210395812988,78.620704581794,3.511564778813712
395000,45.65664196014404,78.620704581794,2.3604755704356934
400000,46.24819898605347,78.620704581794,1.586712838743648
405000,46.81594252586365,78.620704581794,1.0665891501555442
410000,47.385974407196045,78.620704581794,0.7169617510187173
415000,47.95387268066406,78.620704581794,0.4819420414588525
420000,48.52208638191223,78.620704581794,0.3239616771682742
425000,49.088802099227905,78.620704581794,0.21776719863656413
430000,49.656049966812134,78.620704581794,0.14638321796742726
435000,50.22277808189392,78.620704581794,9.8411944181564
440000,50.79074048995972,78.620704581794,6.615255725344727
445000,51.358076333999634,78.620704581794,4.4467781503197195
450000,51.91084337234497,78.620704581794,2.989126458468149
455000,52.478920459747314,78.620704581794,2.009292274693741
460000,53.043365716934204,78.620704581794,1.350647254721015
465000,53.60069131851196,78.620704581794,0.9079057485369901
470000,54.16664910316467,78.620704581794,0.6102946904495621
475000,54.73716902732849,78.620704581794,0.410240390911847
480000,55.32295489311218,78.620704581794,0.2757637924254785
485000,55.890077114105225,78.620704581794,0.18536855682068426
490000,56.457499742507935,78.620704581794,0.12460483501317157
495000,57.0232412815094,78.620704581794,8.37705594831087
500000,57.5935537815094,78.620704581794,5.631061126214188
505000,58.16193985939026,78.620704581794,3.785202057001227
510000,58.728190183639526,78.620704581794,2.5444146833403267
515000,59.27666735649109,78.620704581794,1.7103568008538028
520000,59.84771800041199,78.620704581794,1.1497026822634422
5000,0.6915416717529297,443.7492402983678,0.6721111959865606
10000,1.3146755695343018,443.7492402983678,0.4520495689035214
15000,1.7231664657592773,439.9078521514258,0.3038679424228721
20000,2.1277782917022705,439.9078521514258,0.20426018026358692
25000,2.5334930419921875,435.0390435921546,0.13730379357770844
30000,2.973337411880493,435.0390435921546,9.23079397837336
35000,3.3832550048828125,435.0390435921546,6.204944249678936
40000,3.7914462089538574,435.0390435921546,4.170966574687698
45000,4.204490900039673,435.0390435921546,2.8037257817525405
50000,4.610482931137085,435.0390435921546,1.8846658486714118
55000,5.0188446044921875,435.0390435921546,1.2668733098884215
60000,5.4173479080200195,435.0390435921546,0.8515928616412607
65000,5.86414647102356,435.0390435921546,0.572441140197534
34 changes: 32 additions & 2 deletions sa.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
parser = argparse.ArgumentParser()
parser.add_argument("-d", help="dataset file", default=False)
parser.add_argument("-n", help="noninteractive", default=False)
parser.add_argument("-k", help="trucks", default=1)
args = parser.parse_args()
time_start = None
report_file = open("report.csv", "w")

# Déclaration de fonctions
def generate_cities(howmany = 15, max_coordinates = 100):
def generate_cities(howmany = 20, max_coordinates = 100):
return [random.sample(range(max_coordinates), 2) for _ in range(howmany)]

def generate_random_tour(cities):
Expand Down Expand Up @@ -50,6 +51,10 @@ def distance_between(tour, cities, i, j):
city_count = len(cities)
return sum([math.sqrt(sum([(cities[tour[(k+1) % city_count]][d] - cities[tour[k % city_count]][d])**2 for d in [0,1] ])) for k in [j,j-1,i,i-1]])

def distance_to_next(tour, cities, index):
city_count = len(cities)
return sum([math.sqrt(sum([(cities[tour[(k+1) % city_count]][d] - cities[tour[k % city_count]][d])**2 for d in [0,1] ])) for k in [index]])

def distance(tour, cities):
city_count = len(cities)
return sum([math.sqrt(sum([(cities[tour[(k+1) % city_count]][d] - cities[tour[k % city_count]][d])**2 for d in [0,1] ])) for k in range(city_count)])
Expand Down Expand Up @@ -158,4 +163,29 @@ def SA(cities, temperatures):
report_file.close()

# Affichage de détails
explain_tour(tour, cities)
explain_tour(tour, cities)

# Division en k camions
print("\nDivision en camions\n")
k = int(args.k)
tour_distance = distance(tour, cities)
i = 0
for truck in range(k-1):
distance_cumulee = 0
while distance_cumulee < (tour_distance / k):
curr = tour[i % city_count]
next = tour[(i + 1) % city_count]
distance = distance_to_next(tour, cities, i)

print("Entre {} et {} -> {}".format(cities[tour[i]], cities[tour[i+1]], distance))

distance_cumulee += distance
i += 1

tour.insert(i, tour[0])
tour.insert(i+1, tour[i+1])

live_plot(tour, cities)

while True:
time.sleep(1)

0 comments on commit 98942e1

Please sign in to comment.