Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 2 additions & 37 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ int main(int argc, char** argv) {
std::string router_arg;
std::string limit_arg;
std::string output_file;
std::vector<std::string> heuristic_params_arg;
unsigned exploration_level;

cxxopts::Options options("vroom",
Expand Down Expand Up @@ -85,22 +84,10 @@ int main(int argc, char** argv) {
cxxopts::value<std::string>(cl_args.input));

// we don't want to print debug args on --help
std::optional<unsigned> debug_depth;
std::optional<unsigned> debug_nb_searches;

options.add_options("debug_group")
("e,heuristic-param",
"Heuristic parameter",
cxxopts::value<std::vector<std::string>>(heuristic_params_arg))
("f,apply-tsp-fix",
"apply experimental TSPFix local search operator",
cxxopts::value<bool>(cl_args.apply_TSPFix)->default_value("false"))
("d,depth",
"search depth",
cxxopts::value<std::optional<unsigned>>(debug_depth))
("s,nb-searches",
"number of searches to perform in parallel",
cxxopts::value<std::optional<unsigned>>(debug_nb_searches));
cxxopts::value<bool>(cl_args.apply_TSPFix)->default_value("false"));

// clang-format on
try {
Expand Down Expand Up @@ -164,12 +151,6 @@ int main(int argc, char** argv) {
}
exploration_level = std::min(exploration_level, vroom::MAX_EXPLORATION_LEVEL);
cl_args.set_exploration_level(exploration_level);
if (debug_depth) {
cl_args.depth = debug_depth.value();
}
if (debug_nb_searches) {
cl_args.nb_searches = debug_nb_searches.value();
}

// Determine routing engine (defaults to ROUTER::OSRM).
if (router_arg == "libosrm") {
Expand All @@ -188,21 +169,6 @@ int main(int argc, char** argv) {
cl_args.router = vroom::ROUTER::OSRM;
}

try {
// Force heuristic parameters from the command-line, useful for
// debugging.
std::ranges::transform(heuristic_params_arg,
std::back_inserter(cl_args.h_params),
[](const auto& str_param) {
return vroom::utils::str_to_heuristic_param(
str_param);
});
} catch (const vroom::Exception& e) {
std::cerr << "[Error] " << e.message << std::endl;
vroom::io::write_to_json(e, cl_args.output_file);
exit(e.error_code);
}

// Get input problem from first input file, then positional arg,
// then stdin.
if (!cl_args.input_file.empty()) {
Expand Down Expand Up @@ -238,8 +204,7 @@ int main(int argc, char** argv) {
: problem_instance.solve(cl_args.nb_searches,
cl_args.depth,
cl_args.nb_threads,
cl_args.timeout,
cl_args.h_params);
cl_args.timeout);

// Write solution.
vroom::io::write_to_json(sol,
Expand Down
4 changes: 1 addition & 3 deletions src/problems/cvrp/cvrp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ CVRP::CVRP(const Input& input) : VRP(input) {
Solution CVRP::solve(const unsigned nb_searches,
const unsigned depth,
const unsigned nb_threads,
const Timeout& timeout,
const std::vector<HeuristicParameters>& h_param) const {
const Timeout& timeout) const {
if (_input.vehicles.size() == 1 && !_input.has_skills() &&
_input.zero_amount().empty() && !_input.has_shipments() &&
(_input.jobs.size() <= _input.vehicles[0].max_tasks) &&
Expand All @@ -168,7 +167,6 @@ Solution CVRP::solve(const unsigned nb_searches,
depth,
nb_threads,
timeout,
h_param,
homogeneous_parameters,
heterogeneous_parameters);
}
Expand Down
10 changes: 4 additions & 6 deletions src/problems/cvrp/cvrp.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ class CVRP : public VRP {
public:
explicit CVRP(const Input& input);

Solution
solve(unsigned nb_searches,
unsigned depth,
unsigned nb_threads,
const Timeout& timeout,
const std::vector<HeuristicParameters>& h_param) const override;
Solution solve(unsigned nb_searches,
unsigned depth,
unsigned nb_threads,
const Timeout& timeout) const override;
};

} // namespace vroom
Expand Down
3 changes: 1 addition & 2 deletions src/problems/tsp/tsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ std::vector<Index> TSP::raw_solve(unsigned nb_threads,
Solution TSP::solve(unsigned,
unsigned,
unsigned nb_threads,
const Timeout& timeout,
const std::vector<HeuristicParameters>&) const {
const Timeout& timeout) const {
RawRoute r(_input, 0, 0);
r.set_route(_input, raw_solve(nb_threads, timeout));
return utils::format_solution(_input, {r});
Expand Down
3 changes: 1 addition & 2 deletions src/problems/tsp/tsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ class TSP : public VRP {
Solution solve(unsigned,
unsigned,
unsigned nb_threads,
const Timeout& timeout,
const std::vector<HeuristicParameters>&) const override;
const Timeout& timeout) const override;
};

} // namespace vroom
Expand Down
16 changes: 5 additions & 11 deletions src/problems/vrp.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,9 @@ class VRP {
const unsigned depth,
const unsigned nb_threads,
const Timeout& timeout,
const std::vector<HeuristicParameters>& h_param,
const std::vector<HeuristicParameters>& homogeneous_parameters,
const std::vector<HeuristicParameters>& heterogeneous_parameters) const {
// Use vector of parameters when passed for debugging, else use
// predefined parameter set.
const auto& parameters = (!h_param.empty()) ? h_param
: (_input.has_homogeneous_locations())
const auto& parameters = (_input.has_homogeneous_locations())
? homogeneous_parameters
: heterogeneous_parameters;
assert(nb_searches != 0);
Expand Down Expand Up @@ -273,12 +269,10 @@ class VRP {

virtual ~VRP();

virtual Solution
solve(unsigned nb_searches,
unsigned depth,
unsigned nb_threads,
const Timeout& timeout,
const std::vector<HeuristicParameters>& h_param) const = 0;
virtual Solution solve(unsigned nb_searches,
unsigned depth,
unsigned nb_threads,
const Timeout& timeout) const = 0;
};

} // namespace vroom
Expand Down
4 changes: 1 addition & 3 deletions src/problems/vrptw/vrptw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,11 @@ VRPTW::VRPTW(const Input& input) : VRP(input) {
Solution VRPTW::solve(const unsigned nb_searches,
const unsigned depth,
const unsigned nb_threads,
const Timeout& timeout,
const std::vector<HeuristicParameters>& h_param) const {
const Timeout& timeout) const {
return VRP::solve<TWRoute, vrptw::LocalSearch>(nb_searches,
depth,
nb_threads,
timeout,
h_param,
homogeneous_parameters,
heterogeneous_parameters);
}
Expand Down
10 changes: 4 additions & 6 deletions src/problems/vrptw/vrptw.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ class VRPTW : public VRP {
public:
explicit VRPTW(const Input& input);

Solution
solve(unsigned nb_searches,
unsigned depth,
unsigned nb_threads,
const Timeout& timeout,
const std::vector<HeuristicParameters>& h_param) const override;
Solution solve(unsigned nb_searches,
unsigned depth,
unsigned nb_threads,
const Timeout& timeout) const override;
};

} // namespace vroom
Expand Down
25 changes: 12 additions & 13 deletions src/structures/cl_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@ using Servers =

struct CLArgs {
// Listing command-line options.
Servers servers; // -a and -p
bool check; // -c
std::vector<HeuristicParameters> h_params; // -e
bool apply_TSPFix; // -f
bool geometry; // -g
std::string input_file; // -i
Timeout timeout; // -l
std::string output_file; // -o
ROUTER router; // -r
std::string input; // cl arg
unsigned nb_threads; // -t
unsigned nb_searches; // derived from -x
unsigned depth; // derived from -x
Servers servers; // -a and -p
bool check; // -c
bool apply_TSPFix; // -f
bool geometry; // -g
std::string input_file; // -i
Timeout timeout; // -l
std::string output_file; // -o
ROUTER router; // -r
std::string input; // cl arg
unsigned nb_threads; // -t
unsigned nb_searches; // derived from -x
unsigned depth; // derived from -x

void set_exploration_level(unsigned exploration_level);
};
Expand Down
12 changes: 4 additions & 8 deletions src/structures/vroom/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,20 +1200,17 @@ std::unique_ptr<VRP> Input::get_problem() const {

Solution Input::solve(const unsigned exploration_level,
const unsigned nb_thread,
const Timeout& timeout,
const std::vector<HeuristicParameters>& h_param) {
const Timeout& timeout) {
return solve(utils::get_nb_searches(exploration_level),
utils::get_depth(exploration_level),
nb_thread,
timeout,
h_param);
timeout);
}

Solution Input::solve(const unsigned nb_searches,
const unsigned depth,
const unsigned nb_thread,
const Timeout& timeout,
const std::vector<HeuristicParameters>& h_param) {
const Timeout& timeout) {
run_basic_checks();

if (_has_initial_routes) {
Expand Down Expand Up @@ -1253,8 +1250,7 @@ Solution Input::solve(const unsigned nb_searches,
}

// Solve.
auto sol =
instance->solve(nb_searches, depth, nb_thread, solve_time, h_param);
auto sol = instance->solve(nb_searches, depth, nb_thread, solve_time);

// Update timing info.
sol.summary.computing_times.loading = loading.count();
Expand Down
8 changes: 2 additions & 6 deletions src/structures/vroom/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,13 @@ class Input {
Solution solve(unsigned nb_searches,
unsigned depth,
unsigned nb_thread,
const Timeout& timeout = Timeout(),
const std::vector<HeuristicParameters>& h_param =
std::vector<HeuristicParameters>());
const Timeout& timeout = Timeout());

// Overload designed to expose the same interface as the `-x`
// command-line flag for out-of-the-box setup of exploration level.
Solution solve(unsigned exploration_level,
unsigned nb_thread,
const Timeout& timeout = Timeout(),
const std::vector<HeuristicParameters>& h_param =
std::vector<HeuristicParameters>());
const Timeout& timeout = Timeout());

Solution check(unsigned nb_thread);
};
Expand Down
69 changes: 0 additions & 69 deletions src/utils/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,75 +28,6 @@ Amount max_amount(std::size_t size) {
return max;
}

INIT get_init(std::string_view s) {
using enum INIT;
if (s == "NONE") {
return NONE;
}
if (s == "HIGHER_AMOUNT") {
return HIGHER_AMOUNT;
}
if (s == "NEAREST") {
return NEAREST;
}
if (s == "FURTHEST") {
return FURTHEST;
}
if (s == "EARLIEST_DEADLINE") {
return EARLIEST_DEADLINE;
}
throw InputException("Invalid heuristic parameter in command-line.");
}

SORT get_sort(std::string_view s) {
if (s == "AVAILABILITY") {
return SORT::AVAILABILITY;
}
if (s == "COST") {
return SORT::COST;
}
throw InputException("Invalid heuristic parameter in command-line.");
}

HeuristicParameters str_to_heuristic_param(const std::string& s) {
// Split command-line string describing parameters.
constexpr char delimiter = ';';
std::vector<std::string> tokens;
tokens.reserve(4);
std::string token;
std::istringstream tokenStream(s);
while (std::getline(tokenStream, token, delimiter)) {
tokens.push_back(token);
}

if ((tokens.size() != 3 && tokens.size() != 4) || tokens[0].size() != 1) {
throw InputException("Invalid heuristic parameter in command-line.");
}

auto init = get_init(tokens[1]);
auto sort = (tokens.size() == 3) ? SORT::AVAILABILITY : get_sort(tokens[3]);

try {
auto h = std::stoul(tokens[0]);

if (h != 0 && h != 1) {
throw InputException("Invalid heuristic parameter in command-line.");
}

auto regret_coeff = std::stof(tokens[2]);
if (regret_coeff < 0) {
throw InputException("Invalid heuristic parameter in command-line.");
}

return HeuristicParameters(static_cast<HEURISTIC>(h),
init,
regret_coeff,
sort);
} catch (const std::exception&) {
throw InputException("Invalid heuristic parameter in command-line.");
}
}

Priority priority_sum_for_route(const Input& input,
const std::vector<Index>& route) {
return std::accumulate(route.begin(),
Expand Down
6 changes: 0 additions & 6 deletions src/utils/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ inline unsigned get_nb_searches(unsigned exploration_level) {
return nb_searches;
}

INIT get_init(std::string_view s);

SORT get_sort(std::string_view s);

HeuristicParameters str_to_heuristic_param(const std::string& s);

// Evaluate adding job with rank job_rank in given route at given rank
// for vehicle v.
inline Eval addition_eval(const Input& input,
Expand Down