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
6ea83fb9
Commit
6ea83fb9
authored
3 months ago
by
Jakub Janák
Browse files
Options
Downloads
Patches
Plain Diff
strategy implemented into controller
parent
5c5699ec
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
controller/controller.cpp
+19
-43
19 additions, 43 deletions
controller/controller.cpp
controller/controller.hpp
+9
-6
9 additions, 6 deletions
controller/controller.hpp
with
28 additions
and
49 deletions
controller/controller.cpp
+
19
−
43
View file @
6ea83fb9
#include
"controller.hpp"
#include
"../helper/helper.hpp"
#include
"../files/file_manager.hpp"
#include
"controller_strategy/controller_strategy.hpp"
#include
<iostream>
#include
<random>
...
...
@@ -8,7 +9,7 @@
#include
<fstream>
#include
<string>
controller
::
controller
()
{
controller
::
controller
()
:
cont
(
this
)
{
desc
.
add_options
()
(
"help,h"
,
"Print help message"
)
(
"load-instances,l"
,
boost
::
program_options
::
value
<
std
::
string
>
(),
"Specify load instances file"
)
...
...
@@ -35,7 +36,6 @@ void controller::print_header() {
}
int
controller
::
run
(
const
int
argc
,
char
*
argv
[])
{
// print header every time
print_header
();
try
{
...
...
@@ -43,54 +43,26 @@ int controller::run(const int argc, char *argv[]) {
store
(
parse_command_line
(
argc
,
argv
,
desc
),
vm
);
notify
(
vm
);
// Print help message
if
(
argc
==
1
||
vm
.
contains
(
"help"
))
{
std
::
cout
<<
desc
<<
std
::
endl
;
return
0
;
}
// load / create instances
if
(
vm
.
contains
(
"load-instances"
))
{
const
std
::
string
path
=
vm
[
"load-instances"
].
as
<
std
::
string
>
();
load_instance
(
path
);
}
if
(
vm
.
contains
(
"auto-load-instances"
))
{
auto_load_instances
();
}
if
(
vm
.
contains
(
"create-synthetic-instance"
))
{
const
int
num_of_nodes
=
vm
[
"create-synthetic-instance"
].
as
<
int
>
();
create_synthetic_instance
(
num_of_nodes
);
}
const
auto
parsed
=
boost
::
program_options
::
command_line_parser
(
argc
,
argv
).
options
(
desc
).
allow_unregistered
().
run
();
// solving
if
(
vm
.
contains
(
"solve"
))
{
solve
();
}
store
(
parsed
,
vm
);
notify
(
vm
);
if
(
vm
.
contains
(
"solve-parallel"
))
{
const
int
num_of_threads
=
vm
[
"solve-parallel"
].
as
<
int
>
();
if
(
num_of_threads
<=
0
)
{
std
::
cerr
<<
"Number of threads must be an integer >= 1"
<<
std
::
endl
;
return
1
;
}
if
(
num_of_threads
==
1
)
{
std
::
cerr
<<
"For single threaded solving call --solve"
<<
std
::
endl
;
}
solve
(
num_of_threads
);
// Check for unrecognized commands
auto
unrecognized
=
collect_unrecognized
(
parsed
.
options
,
boost
::
program_options
::
include_positional
);
if
(
!
unrecognized
.
empty
())
{
throw
std
::
runtime_error
(
"Unrecognized command: "
+
unrecognized
[
0
]);
}
// approximation
if
(
vm
.
contains
(
"heuristic-combo"
))
{
heuristic_combo
();
}
return
0
;
}
catch
(
const
boost
::
program_options
::
error
&
ex
)
{
cont
.
run_strategy
(
argc
,
vm
);
}
catch
(
const
std
::
runtime_error
&
error
)
{
std
::
cerr
<<
error
.
what
()
<<
std
::
endl
;
return
1
;
}
catch
(
const
boost
::
program_options
::
error
&
ex
)
{
std
::
cerr
<<
"Error: "
<<
ex
.
what
()
<<
"
\n
"
;
std
::
cerr
<<
desc
<<
"
\n
"
;
return
1
;
}
return
0
;
}
void
controller
::
load_instance
(
const
std
::
string
&
file_name
)
{
...
...
@@ -155,3 +127,7 @@ void controller::heuristic_combo() {
this
->
unsolvedInstances
.
pop_front
();
}
}
boost
::
program_options
::
options_description
controller
::
get_desc
()
{
return
desc
;
}
This diff is collapsed.
Click to expand it.
controller/controller.hpp
+
9
−
6
View file @
6ea83fb9
...
...
@@ -2,31 +2,34 @@
#define CONTROLLER_H
#include
"../graph/ts_instance.hpp"
#include
"controller_strategy/controller_strategy.hpp"
#include
<boost/program_options.hpp>
class
controller
{
std
::
deque
<
std
::
unique_ptr
<
ts_instance
>>
unsolvedInstances
;
std
::
deque
<
std
::
unique_ptr
<
ts_instance
>
>
unsolvedInstances
;
boost
::
program_options
::
options_description
desc
=
{
"Arguments"
};
strategy_context
cont
;
static
void
print_header
();
void
load_instance
(
const
std
::
string
&
file_name
);
public
:
void
load_instance
(
const
std
::
string
&
file_name
);
void
auto_load_instances
();
void
create_synthetic_instance
(
int
num_of_nodes
);
void
solve
(
int
num_of_threads
=
1
);
// not multithreaded by default
// not multithreaded by default
void
solve
(
int
num_of_threads
=
1
);
void
heuristic_combo
();
public
:
controller
();
int
run
(
int
argc
,
char
*
argv
[]);
boost
::
program_options
::
options_description
get_desc
();
};
#endif
//CONTROLLER_H
#endif
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