Skip to content

Commit

Permalink
apply clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Kei18 committed Aug 9, 2021
1 parent 51a69f1 commit d567f7d
Show file tree
Hide file tree
Showing 23 changed files with 337 additions and 340 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ jobs:

- name: run-app
working-directory: build
run: ./mapf -i ../instances/mapf/sample.txt -s PIBT -o result.txt -v
run: ./mapd -i ../instances/mapd/sample.txt -s PIBT -o result.txt -v
run: |
./mapf -i ../instances/mapf/sample.txt -s PIBT -o result.txt -v
./mapd -i ../instances/mapd/sample.txt -s PIBT -o result.txt -v
5 changes: 3 additions & 2 deletions .github/workflows/test-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ jobs:

- name: run-app
working-directory: build
run: ./mapf -i ../instances/mapf/sample.txt -s PIBT -o result.txt -v
run: ./mapd -i ../instances/mapd/sample.txt -s PIBT -o result.txt -v
run: |
./mapf -i ../instances/mapf/sample.txt -s PIBT -o result.txt -v
./mapd -i ../instances/mapd/sample.txt -s PIBT -o result.txt -v
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ target_link_libraries(mapd lib-mapf)
# format
add_custom_target(clang-format
COMMAND clang-format -i
../mapf/include/*.hpp
../mapf/src/*.cpp
../pibt2/include/*.hpp
../pibt2/src/*.cpp
../tests/*.cpp
../mapf.cpp
../mapd.cpp)
Expand Down
37 changes: 29 additions & 8 deletions instances/mapd/sample.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
map_file=8x8.map
agents=2
## ==== necessary ====
## .map file, put your maps in /map folder
map_file=warehouse.map

## number of agents
agents=50

## ==== custom =======
## seed of randomization
seed=0
max_timestep=100
max_comp_time=1000
random_problem=0

## timestep limit
max_timestep=3000

## computation time limit, ms
max_comp_time=10000

## task frequency, 0-1, 2, 3, ...
task_frequency=1
task_num=10
1,1
3,1

## number of tasks
task_num=500

## specify pickup and delivery location, use .pd file
specify_pickup_deliv_locs=1

## custom starts
## (x_s, y_s)
## (0, 0): left-top corner
# 0,0
# 3,1
8 changes: 0 additions & 8 deletions instances/mapd/toy.txt

This file was deleted.

46 changes: 25 additions & 21 deletions mapd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
#include <default_params.hpp>
#include <iostream>
#include <pibt_mapd.hpp>
#include <tp.hpp>
#include <problem.hpp>
#include <random>
#include <tp.hpp>
#include <vector>

void printHelp();
std::unique_ptr<MAPD_Solver> getSolver(const std::string solver_name, MAPD_Instance* P,
bool verbose, int argc, char* argv[], bool use_distance_table);
std::unique_ptr<MAPD_Solver> getSolver(const std::string solver_name,
MAPD_Instance* P, bool verbose, int argc,
char* argv[], bool use_distance_table);

int main(int argc, char* argv[])
{
Expand Down Expand Up @@ -39,7 +40,8 @@ int main(int argc, char* argv[])
// command line args
int opt, longindex;
opterr = 0; // ignore getopt error
while ((opt = getopt_long(argc, argv, "i:o:s:vhT:Ld", longopts, &longindex)) != -1) {
while ((opt = getopt_long(argc, argv, "i:o:s:vhT:Ld", longopts,
&longindex)) != -1) {
switch (opt) {
case 'i':
instance_file = std::string(optarg);
Expand Down Expand Up @@ -84,11 +86,12 @@ int main(int argc, char* argv[])
if (max_comp_time != -1) P.setMaxCompTime(max_comp_time);

// solve
auto solver = getSolver(solver_name, &P, verbose, argc, argv_copy, use_distance_table);
auto solver =
getSolver(solver_name, &P, verbose, argc, argv_copy, use_distance_table);
solver->setLogShort(log_short);
solver->solve();
if (solver->succeed() && !solver->getSolution().validate(&P)) {
std::cout << "error@app: invalid results" << std::endl;
std::cout << "error@mapd: invalid results" << std::endl;
return 0;
}
solver->printResult();
Expand All @@ -102,17 +105,17 @@ int main(int argc, char* argv[])
return 0;
}

std::unique_ptr<MAPD_Solver> getSolver(const std::string solver_name, MAPD_Instance* P,
bool verbose, int argc, char* argv[],
bool use_distance_table)
std::unique_ptr<MAPD_Solver> getSolver(const std::string solver_name,
MAPD_Instance* P, bool verbose, int argc,
char* argv[], bool use_distance_table)
{
std::unique_ptr<MAPD_Solver> solver;
if (solver_name == "PIBT") {
solver = std::make_unique<PIBT_MAPD>(P, use_distance_table);
} else if (solver_name == "TP") {
solver = std::make_unique<TP>(P, use_distance_table);
} else {
std::cout << "warn@app: "
std::cout << "warn@mapd: "
<< "unknown solver name, " + solver_name + ", continue by PIBT"
<< std::endl;
solver = std::make_unique<PIBT_MAPD>(P, use_distance_table);
Expand All @@ -124,17 +127,18 @@ std::unique_ptr<MAPD_Solver> getSolver(const std::string solver_name, MAPD_Insta

void printHelp()
{
std::cout << "\nUsage: ./app [OPTIONS] [SOLVER-OPTIONS]\n"
<< "\n**instance file is necessary to run MAPF simulator**\n\n"
<< " -i --instance [FILE_PATH] instance file path\n"
<< " -o --output [FILE_PATH] ouptut file path\n"
<< " -v --verbose print additional info\n"
<< " -h --help help\n"
<< " -d --use-distance-table use pre-computed distance table\n"
<< " -s --solver [SOLVER_NAME] solver, choose from the below\n"
<< " -T --time-limit [INT] max computation time (ms)\n"
<< " -L --log-short use short log\n"
<< "\n\nSolver Options:" << std::endl;
std::cout
<< "\nUsage: ./mapd [OPTIONS] [SOLVER-OPTIONS]\n"
<< "\n**instance file is necessary to run MAPD simulator**\n\n"
<< " -i --instance [FILE_PATH] instance file path\n"
<< " -o --output [FILE_PATH] ouptut file path\n"
<< " -v --verbose print additional info\n"
<< " -h --help help\n"
<< " -d --use-distance-table use pre-computed distance table\n"
<< " -s --solver [SOLVER_NAME] solver, choose from the below\n"
<< " -T --time-limit [INT] max computation time (ms)\n"
<< " -L --log-short use short log\n"
<< "\nSolver Options:" << std::endl;
// each solver
PIBT_MAPD::printHelp();
TP::printHelp();
Expand Down
26 changes: 14 additions & 12 deletions mapf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
#include <iostream>
#include <pibt.hpp>
#include <pibt_plus.hpp>
#include <push_and_swap.hpp>
#include <problem.hpp>
#include <push_and_swap.hpp>
#include <random>
#include <vector>

void printHelp();
std::unique_ptr<MAPF_Solver> getSolver(const std::string solver_name, MAPF_Instance* P,
bool verbose, int argc, char* argv[]);
std::unique_ptr<MAPF_Solver> getSolver(const std::string solver_name,
MAPF_Instance* P, bool verbose, int argc,
char* argv[]);

int main(int argc, char* argv[])
{
Expand Down Expand Up @@ -41,8 +42,8 @@ int main(int argc, char* argv[])
// command line args
int opt, longindex;
opterr = 0; // ignore getopt error
while ((opt = getopt_long(argc, argv, "i:o:s:vhPT:L", longopts, &longindex)) !=
-1) {
while ((opt = getopt_long(argc, argv, "i:o:s:vhPT:L", longopts,
&longindex)) != -1) {
switch (opt) {
case 'i':
instance_file = std::string(optarg);
Expand All @@ -60,8 +61,8 @@ int main(int argc, char* argv[])
printHelp();
return 0;
case 'P':
make_scen = true;
break;
make_scen = true;
break;
case 'L':
log_short = true;
break;
Expand Down Expand Up @@ -97,7 +98,7 @@ int main(int argc, char* argv[])
solver->setLogShort(log_short);
solver->solve();
if (solver->succeed() && !solver->getSolution().validate(&P)) {
std::cout << "error@app: invalid results" << std::endl;
std::cout << "error@mapf: invalid results" << std::endl;
return 0;
}
solver->printResult();
Expand All @@ -111,8 +112,9 @@ int main(int argc, char* argv[])
return 0;
}

std::unique_ptr<MAPF_Solver> getSolver(const std::string solver_name, MAPF_Instance* P,
bool verbose, int argc, char* argv[])
std::unique_ptr<MAPF_Solver> getSolver(const std::string solver_name,
MAPF_Instance* P, bool verbose, int argc,
char* argv[])
{
std::unique_ptr<MAPF_Solver> solver;
if (solver_name == "PIBT") {
Expand All @@ -124,7 +126,7 @@ std::unique_ptr<MAPF_Solver> getSolver(const std::string solver_name, MAPF_Insta
} else if (solver_name == "PushAndSwap") {
solver = std::make_unique<PushAndSwap>(P);
} else {
std::cout << "warn@app: "
std::cout << "warn@mapf: "
<< "unknown solver name, " + solver_name + ", continue by PIBT"
<< std::endl;
solver = std::make_unique<PIBT>(P);
Expand All @@ -136,7 +138,7 @@ std::unique_ptr<MAPF_Solver> getSolver(const std::string solver_name, MAPF_Insta

void printHelp()
{
std::cout << "\nUsage: ./app [OPTIONS] [SOLVER-OPTIONS]\n"
std::cout << "\nUsage: ./mapf [OPTIONS] [SOLVER-OPTIONS]\n"
<< "\n**instance file is necessary to run MAPF simulator**\n\n"
<< " -i --instance [FILE_PATH] instance file path\n"
<< " -o --output [FILE_PATH] ouptut file path\n"
Expand Down
36 changes: 14 additions & 22 deletions pibt2/include/problem.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once
#include <random>
#include <graph.hpp>
#include <random>

#include "default_params.hpp"
#include "util.hpp"
#include "task.hpp"
#include "util.hpp"

using Config = std::vector<Node*>; // < loc_0[t], loc_1[t], ... >
using Configs = std::vector<Config>;
Expand Down Expand Up @@ -32,7 +32,6 @@ using Configs = std::vector<Config>;
return cost;
}


class Problem
{
protected:
Expand All @@ -50,17 +49,12 @@ class Problem
void warn(const std::string& msg) const;

public:
Problem() {};
Problem(const std::string& _instance): instance(_instance) {}
Problem(std::string _instance,
Graph* _G,
std::mt19937* _MT,
Config _config_s,
Config _config_g,
int _num_agents,
int _max_timestep,
Problem(){};
Problem(const std::string& _instance) : instance(_instance) {}
Problem(std::string _instance, Graph* _G, std::mt19937* _MT, Config _config_s,
Config _config_g, int _num_agents, int _max_timestep,
int _max_comp_time);
~Problem() {};
~Problem(){};

Graph* getG() { return G; }
int getNum() { return num_agents; }
Expand All @@ -76,7 +70,7 @@ class Problem
void setMaxCompTime(const int t) { max_comp_time = t; }
};

class MAPF_Instance: public Problem
class MAPF_Instance : public Problem
{
private:
const bool instance_initialized; // for memory manage
Expand All @@ -89,9 +83,8 @@ class MAPF_Instance: public Problem

public:
MAPF_Instance(const std::string& _instance);
MAPF_Instance(MAPF_Instance* P,
Config _config_s, Config _config_g, int _max_comp_time,
int _max_timestep);
MAPF_Instance(MAPF_Instance* P, Config _config_s, Config _config_g,
int _max_comp_time, int _max_timestep);
MAPF_Instance(MAPF_Instance* P, int _max_comp_time);
~MAPF_Instance();

Expand All @@ -101,8 +94,7 @@ class MAPF_Instance: public Problem
void makeScenFile(const std::string& output_file);
};


class MAPD_Instance: public Problem
class MAPD_Instance : public Problem
{
private:
float task_frequency;
Expand All @@ -112,10 +104,10 @@ class MAPD_Instance: public Problem
Tasks TASKS_OPEN;
Tasks TASKS_CLOSED;

Nodes LOCS_PICKUP; // candidates of pickup locations
Nodes LOCS_DELIVERY; // candidates of delivery locations
Nodes LOCS_PICKUP; // candidates of pickup locations
Nodes LOCS_DELIVERY; // candidates of delivery locations
Nodes LOCS_NONTASK_ENDPOINTS; // endpoints, not necessary for PIBT
Nodes LOCS_ENDPOINTS; // pickup, delivery, nontasks
Nodes LOCS_ENDPOINTS; // pickup, delivery, nontasks

bool specify_pickup_deliv_locs;
void setupSpetialNodes();
Expand Down
6 changes: 2 additions & 4 deletions pibt2/include/push_and_swap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class PushAndSwap : public MAPF_Solver
static const std::string SOLVER_NAME;

private:
bool flg_compress; // whether to compress solution
bool disable_dist_init; // prioritization depending on distance
bool flg_compress; // whether to compress solution
bool disable_dist_init; // prioritization depending on distance
Nodes nodes_with_many_neighbors; // nodes of degree >= 3
bool emergency_stop;

Expand All @@ -35,7 +35,6 @@ class PushAndSwap : public MAPF_Solver
bool swap(Plan& plan, const int i, Nodes& U, std::vector<int>& occupied_now,
std::vector<int>& recursive_list);


// improve solution quality, see
Plan compress(const Plan& plan);

Expand All @@ -58,7 +57,6 @@ class PushAndSwap : public MAPF_Solver
bool resolve(Plan& plan, const int r, const int s, Nodes& U,
std::vector<int>& occupied_now);


// ---------------------------------------
// utilities

Expand Down
Loading

0 comments on commit d567f7d

Please sign in to comment.