Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iv126
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ondřej Chlubna
iv126
Commits
f4c5e032
There was an error fetching the commit references. Please try again later.
Commit
f4c5e032
authored
4 months ago
by
Ondřej Chlubna
Browse files
Options
Downloads
Patches
Plain Diff
matrix_calculation
parent
00e52dc0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.py
+8
-9
8 additions, 9 deletions
main.py
solution.py
+12
-2
12 additions, 2 deletions
solution.py
with
20 additions
and
11 deletions
main.py
+
8
−
9
View file @
f4c5e032
import
random
import
sys
import
sys
import
json
import
json
import
time
from
solution
import
*
from
solution
import
*
...
@@ -16,16 +14,18 @@ def write_instance_json(solution, file_path):
...
@@ -16,16 +14,18 @@ def write_instance_json(solution, file_path):
def
print_our_solution
(
best_route
,
best_cost
):
def
print_our_solution
(
best_route
,
best_cost
):
print
(
"
My
route:
"
,
best_route
)
print
(
"
Our
route:
"
,
best_route
)
print
(
"
My
cost:
"
,
round
(
best_cost
))
print
(
"
Our
cost:
"
,
round
(
best_cost
))
def
print_best_solution
(
instance
):
def
print_best_solution
(
instance
):
print
(
"
Best route:
"
,
instance
[
'
GlobalBest
'
])
print
(
"
Best route:
"
,
instance
[
'
GlobalBest
'
])
print
(
"
Best cost:
"
,
instance
[
'
GlobalBestVal
'
])
print
(
"
Best cost:
"
,
instance
[
'
GlobalBestVal
'
])
# TODO: insted of calculate_distance create incremental evaluation
# TODO: look for better hypermarameters
# TODO: instead of calculate_distance create incremental evaluation
# TODO: look into distance calculation. It seems the matrices are inaccurate because they use only int
# TODO: look for better hyperparameters
# TODO: are these methods the best possible ones?
# TODO: are these methods the best possible ones?
instance_path
=
sys
.
argv
[
1
]
instance_path
=
sys
.
argv
[
1
]
...
@@ -33,9 +33,9 @@ output_path = sys.argv[2]
...
@@ -33,9 +33,9 @@ output_path = sys.argv[2]
instance
=
read_instance_json
(
instance_path
)
instance
=
read_instance_json
(
instance_path
)
best_route
,
best_cost
=
lns
(
instance
[
'
Coordinates
'
],
instance
[
'
Timeout
'
]
-
1
)
best_route
,
best_cost
=
lns
(
instance
[
'
Matrix
'
],
instance
[
'
Coordinates
'
],
instance
[
'
Timeout
'
]
-
1
)
# TODO: before submi
t
ion comment out the next part
# TODO: before submi
ss
ion comment out the next part
print_our_solution
(
best_route
,
best_cost
)
print_our_solution
(
best_route
,
best_cost
)
print_best_solution
(
instance
)
print_best_solution
(
instance
)
...
@@ -57,4 +57,3 @@ write_instance_json(best_route, output_path)
...
@@ -57,4 +57,3 @@ write_instance_json(best_route, output_path)
# ...
# ...
#######################################################################
#######################################################################
#######################################################################
#######################################################################
This diff is collapsed.
Click to expand it.
solution.py
+
12
−
2
View file @
f4c5e032
...
@@ -45,8 +45,18 @@ def zero_start(route):
...
@@ -45,8 +45,18 @@ def zero_start(route):
return
[
0
]
+
route
[
zero_index
+
1
:]
+
route
[:
zero_index
]
return
[
0
]
+
route
[
zero_index
+
1
:]
+
route
[:
zero_index
]
def
lns
(
coords
,
time_limit
=
120
,
destroy_fraction
=
0.2
):
def
print_travels
(
route
,
matrix
):
# it seems the matrix provided is inaccurate
route
=
zero_start
(
route
)
distance
=
0
for
i
in
range
(
len
(
route
)
-
1
):
distance
+=
matrix
[
route
[
i
]][
route
[
i
+
1
]]
print
(
route
[
i
],
distance
,
matrix
[
route
[
i
]][
route
[
i
+
1
]])
distance
+=
matrix
[
route
[
-
1
]][
route
[
0
]]
print
(
route
[
-
1
],
distance
,
matrix
[
route
[
-
1
]][
route
[
0
]])
def
lns
(
matrix
,
coords
,
time_limit
=
120
,
destroy_fraction
=
0.2
):
# it seems the matrices provided are inaccurate, cause they don't use floats
# TODO: look into this
# TODO: look into this
matrix
=
distance_matrix
(
coords
)
matrix
=
distance_matrix
(
coords
)
curr_route
=
greedy
(
matrix
)
curr_route
=
greedy
(
matrix
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment