Skip to content

Commit

Permalink
feat([optimization]): add optimize option
Browse files Browse the repository at this point in the history
  • Loading branch information
HarukiMoriarty committed Jun 23, 2024
1 parent 8426b6d commit 2ece262
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion calmapf/include/instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct Instance {
Graph graph; // graph
Config starts; // initial configuration
Config goals; // goal configuration, can be in warehouse block/cache block
Config garbages; // old goal configuration, used for trash collection
Config garbages; // old goal configuration, used for trash collection
Config cargo_goals; // cargo goal configuration
std::vector<uint> cargo_cnts; // each cargo cnts, help variable for cargo_steps
std::vector<uint> cargo_steps; // each cargo steps
Expand Down
3 changes: 3 additions & 0 deletions calmapf/include/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ struct Parser {
// Logger
std::shared_ptr<spdlog::logger> parser_console;

// Optimize
bool optimization;

Parser(int argc, char* argv[]);
void _post_parse();
void _check();
Expand Down
28 changes: 15 additions & 13 deletions calmapf/src/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ uint Instance::update_on_reaching_goals_with_cache(
j, *cargo_goals[j], *goals[j]);
bit_status[j] = 6;
assert(graph.cache->update_cargo_from_cache(cargo_goals[j], goals[j]));
// Update goals and steps
// Update goals
goals[j] = graph.unloading_ports[cargo_goals[j]->group];
}
// Status 4 finished. ==> Status 6
Expand All @@ -101,7 +101,7 @@ uint Instance::update_on_reaching_goals_with_cache(
j, *cargo_goals[j], *goals[j]);
bit_status[j] = 6;
assert(graph.cache->update_cargo_into_cache(cargo_goals[j], goals[j]));
// Update goals and steps
// Update goals
goals[j] = graph.unloading_ports[cargo_goals[j]->group];
}
}
Expand All @@ -115,15 +115,16 @@ uint Instance::update_on_reaching_goals_with_cache(
// Agent has moved to warehouse cargo target
CacheAccessResult result = graph.cache->try_insert_cache(cargo_goals[j], graph.unloading_ports[agent_group[j]]);
// Cache is full, directly get back to unloading port.
// ==> Status 6
// ==> Status 5
if (!result.result) {
instance_console->debug(
"Agent {} status 1 -> status 5, reach warehouse cargo {}, cache "
"is full, go back to unloading port",
j, *cargo_goals[j]);
bit_status[j] = 5;
}
// Find empty cache block, go and insert cargo into cache, -> Status 5
// Find empty cache block, go and insert cargo into cache.
// ==> Status 4
else {
instance_console->debug(
"Agent {} status 1 -> status 4, reach warehouse cargo {}, find "
Expand Down Expand Up @@ -224,16 +225,17 @@ uint Instance::update_on_reaching_goals_with_cache(
// Agent has yet not back to unloading port, we check if there is an empty
// cache block to insert
else {
CacheAccessResult result = graph.cache->try_insert_cache(cargo_goals[j], graph.unloading_ports[agent_group[j]]);
// Check if the cache is available during the period
if (result.result) {
instance_console->debug(
"Agent {} status 3 -> status 4, find cache block to insert during the moving, go to cache block {}",
j, *cargo_goals[j], *result.goal);
bit_status[j] = 4;
goals[j] = result.goal;
if (parser->optimization) {
CacheAccessResult result = graph.cache->try_insert_cache(cargo_goals[j], graph.unloading_ports[agent_group[j]]);
// Check if the cache is available during the period
if (result.result) {
instance_console->debug(
"Agent {} status 3 -> status 4, find cache block to insert during the moving, go to cache block {}",
j, *cargo_goals[j], *result.goal);
bit_status[j] = 4;
goals[j] = result.goal;
}
}
// Otherwise, we do nothing if the cache miss
}
}
else if (bit_status[j] == 6) {
Expand Down
4 changes: 4 additions & 0 deletions calmapf/src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Parser::Parser(int argc, char* argv[]) {
program.add_argument("-vof", "--visual-output-file").help("Path to the visual output file. Defaults to './result/vis.yaml'.").default_value(std::string("./result/vis.yaml"));
program.add_argument("-slf", "--short-log-format").help("Enable short log format. Implicitly true when set.").default_value(false).implicit_value(true);
program.add_argument("-dl", "--debug-log").help("Enable debug logging. Implicitly true when set.").default_value(false).implicit_value(true);
program.add_argument("-op", "--optimize").help("Enable optimization. Enable checking empty space for cache insert while moving.").default_value(false).implicit_value(true);

try {
program.parse_known_args(argc, argv);
Expand Down Expand Up @@ -65,6 +66,8 @@ Parser::Parser(int argc, char* argv[]) {
short_log_format = program.get<bool>("short-log-format");
debug_log = program.get<bool>("debug-log");

optimization = program.get<bool>("debug-log");

// Post parse
_post_parse();

Expand Down Expand Up @@ -155,6 +158,7 @@ void Parser::_print() {
parser_console->info("Visual file: {}", output_visual_file);
parser_console->info("Log short: {}", short_log_format);
parser_console->info("Debug: {}", debug_log);
parser_console->info("Optimization: {}", optimization);
}

// Unit test only
Expand Down

0 comments on commit 2ece262

Please sign in to comment.