Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tss
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Jakub Janák
tss
Commits
b464955e
Commit
b464955e
authored
3 months ago
by
Jakub Janák
Browse files
Options
Downloads
Patches
Plain Diff
method ge_min_cost made public
parent
2f4ff9d7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
graph/ts_instance.cpp
+3
-5
3 additions, 5 deletions
graph/ts_instance.cpp
graph/ts_instance.hpp
+4
-3
4 additions, 3 deletions
graph/ts_instance.hpp
with
7 additions
and
8 deletions
graph/ts_instance.cpp
+
3
−
5
View file @
b464955e
...
...
@@ -127,12 +127,13 @@ void ts_instance::branch_parallel(std::vector<node> visitedNodes, double cost, c
}
}
// After all neighbors are posted to the thread pool, handle the first neighbor immediately
// After all
,
neighbors are posted to the thread pool, handle the first neighbor immediately
if
(
firstNeighbour
)
{
branch_parallel
(
firstBranchVisNodes
,
firstSendCost
,
*
firstNeighbour
);
}
if
(
visitedNodes
.
size
()
==
nodes
.
size
())
{
std
::
lock_guard
lock
(
m_1
);
cost
+=
get_cost_between_nodes
(
visitedNodes
.
back
(),
startingNode
);
if
(
cost
<
get_min_cost
())
{
set_min_cost
(
cost
);
...
...
@@ -204,12 +205,11 @@ double ts_instance::heuristic_combo() const {
}
double
ts_instance
::
get_min_cost
()
{
std
::
lock_guard
lock
(
m_
1
);
std
::
lock_guard
lock
(
m_
2
);
return
this
->
minCost
;
}
void
ts_instance
::
set_min_cost
(
const
double
minCost
)
{
std
::
lock_guard
lock
(
m_1
);
this
->
minCost
=
minCost
;
}
...
...
@@ -218,12 +218,10 @@ bool ts_instance::is_solved() const {
}
void
ts_instance
::
clear_best_hams
()
{
std
::
lock_guard
lock
(
m_1
);
this
->
bestHamiltonianPaths
.
clear
();
}
void
ts_instance
::
add_best_hamiltonian
(
const
std
::
vector
<
node
>
&
path
)
{
std
::
lock_guard
lock
(
m_1
);
this
->
bestHamiltonianPaths
.
push_back
(
path
);
}
...
...
This diff is collapsed.
Click to expand it.
graph/ts_instance.hpp
+
4
−
3
View file @
b464955e
...
...
@@ -8,7 +8,8 @@
class
ts_instance
:
public
graph
{
std
::
mutex
m_1
;
// mutex for thread safety of minCost
std
::
mutex
m_1
;
std
::
mutex
m_2
;
std
::
unique_ptr
<
boost
::
asio
::
thread_pool
>
pool
;
double
minCost
;
// thread save minimal cost variable
node
startingNode
;
...
...
@@ -28,8 +29,6 @@ class ts_instance : public graph {
static
double
two_opt
(
std
::
vector
<
node
>
greedyPath
);
[[
nodiscard
]]
double
get_min_cost
();
void
set_min_cost
(
double
minCost
);
void
clear_best_hams
();
...
...
@@ -37,6 +36,8 @@ class ts_instance : public graph {
void
add_best_hamiltonian
(
const
std
::
vector
<
node
>
&
path
);
public
:
[[
nodiscard
]]
double
get_min_cost
();
ts_instance
(
std
::
vector
<
std
::
shared_ptr
<
node
>
>
nodes
,
std
::
vector
<
std
::
shared_ptr
<
edge
>
>
edges
);
std
::
vector
<
std
::
vector
<
node
>
>
solve
(
int
num_of_threads
=
1
);
...
...
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