Skip to content
Draft
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
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ add_custom_target(clean_all
)


add_custom_target(lint
COMMAND ${CMAKE_COMMAND}
-DCHECK_NO_AUTO_SOURCE_DIR=${CMAKE_SOURCE_DIR}
-P ${CMAKE_SOURCE_DIR}/cmake/CheckNoAuto.cmake
COMMENT "Checking coding style"
)


set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
"${CMAKE_BINARY_DIR}/lifelong;
${CMAKE_BINARY_DIR}/build;
Expand All @@ -61,6 +69,11 @@ set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
option(BUILD_TESTS "Build planner tests" ON)
if(BUILD_TESTS)
enable_testing()
add_test(NAME no_auto_lint
COMMAND ${CMAKE_COMMAND}
-DCHECK_NO_AUTO_SOURCE_DIR=${CMAKE_SOURCE_DIR}
-P ${CMAKE_SOURCE_DIR}/cmake/CheckNoAuto.cmake)

add_executable(multi_step_plan_test
tests/multi_step_plan_test.cpp
${DEFAULT_PLANNER_SOURCES}
Expand Down Expand Up @@ -89,4 +102,3 @@ if(BUILD_TESTS)
add_test(NAME python_interface_test COMMAND python_interface_test
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
endif()

13 changes: 13 additions & 0 deletions Coding_Style.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Coding Style

The start kit uses C++17. Prefer clear, explicit types in public and starter code so submissions remain easy to read and debug.

## Linting

Run the style check from a configured build directory:

```shell
cmake --build build --target lint
```

The `lint` target rejects use of the C++ `auto` keyword in start-kit source and test files. Use explicit types instead.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ cmake -B build ./ -DCMAKE_BUILD_TYPE=Release
make -C build -j
```

## Coding style

See [Coding_Style.md](./Coding_Style.md). After configuring CMake, run `cmake --build build --target lint` to check the no-`auto` style rule.

## Run the start kit

Running the start-kit using commands:
Expand Down
40 changes: 40 additions & 0 deletions cmake/CheckNoAuto.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
set(CHECK_NO_AUTO_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/.." CACHE PATH "Repository root to scan")

set(CHECK_NO_AUTO_PATTERNS
"default_planner/*.cpp"
"default_planner/*.h"
"inc/*.h"
"src/*.cpp"
"src/*.h"
"tests/*.cpp"
"tests/*.h"
"python/common/*.cpp"
"python/common/*.h")

set(files)
foreach(pattern IN LISTS CHECK_NO_AUTO_PATTERNS)
file(GLOB matched "${CHECK_NO_AUTO_SOURCE_DIR}/${pattern}")
list(APPEND files ${matched})
endforeach()

set(found_auto FALSE)
foreach(file IN LISTS files)
if(file MATCHES "/inc/nlohmann/")
continue()
endif()
file(STRINGS "${file}" lines)
set(line_number 0)
foreach(line IN LISTS lines)
math(EXPR line_number "${line_number} + 1")
string(REGEX REPLACE "//.*$" "" code "${line}")
if(code MATCHES "(^|[^A-Za-z0-9_])auto([ \\t\\*&]+|$)")
file(RELATIVE_PATH rel "${CHECK_NO_AUTO_SOURCE_DIR}" "${file}")
message(SEND_ERROR "${rel}:${line_number}: use explicit types instead of auto")
set(found_auto TRUE)
endif()
endforeach()
endforeach()

if(found_auto)
message(FATAL_ERROR "Found forbidden C++ auto keyword usage")
endif()
4 changes: 2 additions & 2 deletions default_planner/default_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ vector<State> execute_process_new_plan(int sync_time_limit, Plan& plan_struct, v
previous_locations[i] = env->system_states[i].location; //for use of keep track of tpg in move function
}

auto curr_states = predicted_states;
std::vector<State> curr_states = predicted_states;

int moves[4] = {1, env->cols, -1, -env->cols};
std::vector<std::vector<Action>> plan = plan_struct.actions;
Expand Down Expand Up @@ -102,7 +102,7 @@ vector<State> execute_process_new_plan(int sync_time_limit, Plan& plan_struct, v

for (int t = 0; t < window_size; t++)
{
auto pre_states = curr_states;
std::vector<State> pre_states = curr_states;
for (int i = 0; i < env->num_of_agents; i++)
{

Expand Down
10 changes: 5 additions & 5 deletions default_planner/heuristics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void init_heuristic(HeuristicTable& ht, SharedEnvironment* env, int goal_locatio


int get_heuristic(HeuristicTable& ht, SharedEnvironment* env, int source, Neighbors* ns){
auto it = ht.htable.find(source);
std::unordered_map<int, int>::iterator it = ht.htable.find(source);
if (it != ht.htable.end() && it->second < MAX_TIMESTEP) return it->second;

std::vector<int> neighbors;
Expand All @@ -75,7 +75,7 @@ int get_heuristic(HeuristicTable& ht, SharedEnvironment* env, int source, Neighb
assert(next >= 0 && next < env->map.size());
//set current cost for reversed direction

auto it = ht.htable.find(next);
std::unordered_map<int, int>::iterator it = ht.htable.find(next);
if (it != ht.htable.end() && it->second <= cost) // if 'next' is not found in htable, that means it's MAX_TIMESTEP
continue;

Expand Down Expand Up @@ -122,7 +122,7 @@ void init_dist_2_path(Dist2Path& dp, SharedEnvironment* env, Traj& path){
int loc = path[i];

// If this location has already been visited in this label, skip it
auto it = dp.dist2path.find(loc);
std::unordered_map<int, d2p>::iterator it = dp.dist2path.find(loc);
if (it != dp.dist2path.end() && it->second.label == dp.label) {
assert(it->second.cost == MAX_TIMESTEP);
}
Expand All @@ -138,7 +138,7 @@ void init_dist_2_path(Dist2Path& dp, SharedEnvironment* env, Traj& path){

std::pair<int,int> get_source_2_path(Dist2Path& dp, SharedEnvironment* env, int source, Neighbors* ns)
{
auto it_source = dp.dist2path.find(source);
std::unordered_map<int, d2p>::iterator it_source = dp.dist2path.find(source);
if (it_source != dp.dist2path.end() && it_source->second.label == dp.label && it_source->second.cost < MAX_TIMESTEP)
return std::make_pair(it_source->second.cost, it_source->second.togo);

Expand All @@ -153,7 +153,7 @@ std::pair<int,int> get_source_2_path(Dist2Path& dp, SharedEnvironment* env, int
for (int next_location : neighbors)
{
cost = curr.cost + 1;
auto it_next = dp.dist2path.find(next_location);
std::unordered_map<int, d2p>::iterator it_next = dp.dist2path.find(next_location);
if (it_next != dp.dist2path.end() && it_next->second.label == dp.label && cost >= it_next->second.cost)
continue;
dp.open.emplace_back(dp.label,next_location,cost,curr.togo);
Expand Down
4 changes: 2 additions & 2 deletions default_planner/pibt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool causalPIBT(int curr_id, int higher_id,std::vector<State>& prev_states,
std::vector<int> neighbors;
std::vector<PIBT_C> successors;
getNeighborLocs(&(lns.neighbors),neighbors,prev_loc);
for (auto& neighbor: neighbors){
for (int& neighbor: neighbors){

assert(validateMove(prev_loc, neighbor, lns.env));

Expand Down Expand Up @@ -98,7 +98,7 @@ bool causalPIBT(int curr_id, int higher_id,std::vector<State>& prev_states,
});


for (auto& next: successors){
for (PIBT_C& next: successors){
if(occupied[next.location] && !(higher_id == -1 && prev_loc == next.location))
continue;
assert(validateMove(prev_loc, next.location, lns.env));
Expand Down
10 changes: 5 additions & 5 deletions default_planner/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ namespace DefaultPlanner{
static void run_multistep_pibt_once(SharedEnvironment* env, std::vector<double>& local_priority,
std::vector<Action>& one_step_actions)
{
const auto start_time = std::chrono::steady_clock::now();
const TimePoint start_time = std::chrono::steady_clock::now();
std::sort(ids.begin(), ids.end(), [&](int a, int b) {
return local_priority.at(a) > local_priority.at(b);
}
Expand Down Expand Up @@ -264,7 +264,7 @@ namespace DefaultPlanner{

prev_states = next_states;

const auto elapsed_us = std::chrono::duration_cast<std::chrono::microseconds>(
const long elapsed_us = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now() - start_time).count();
}

Expand Down Expand Up @@ -353,7 +353,7 @@ namespace DefaultPlanner{
return;
}

const auto episode_start = std::chrono::steady_clock::now();
const TimePoint episode_start = std::chrono::steady_clock::now();
const TimePoint episode_deadline = episode_start + std::chrono::milliseconds(std::max(0, time_limit));
int pibt_time = PIBT_RUNTIME_PER_100_AGENTS * env->num_of_agents/100;
if (pibt_time <= 0){
Expand All @@ -377,8 +377,8 @@ namespace DefaultPlanner{
setup_multistep_episode_state(env, flow_end_time, local_priority);
update_guide_paths_once_for_multistep(env, flow_end_time);

const auto after_setup = std::chrono::steady_clock::now();
const auto setup_elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(after_setup - episode_start).count();
const TimePoint after_setup = std::chrono::steady_clock::now();
const long setup_elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(after_setup - episode_start).count();
// commit only cross-episode priority update (internal rollout keeps using local_priority only)
p = local_priority;

Expand Down
2 changes: 1 addition & 1 deletion inc/CompetitionSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class BaseSystem
// BaseSystem(grid, planner, model)
// {
// int task_id = 0;
// for (auto& task_location: tasks)
// for (int& task_location: tasks)
// {
// all_tasks.emplace_back(task_id++, task_location);
// task_queue.emplace_back(all_tasks.back().task_id, all_tasks.back().locations.front());
Expand Down
2 changes: 1 addition & 1 deletion inc/States.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ typedef std::vector<State> Path;

inline std::ostream & operator << (std::ostream &out, const Path &path)
{
for (auto state : path)
for (State state : path)
{
if (state.location < 0)
continue;
Expand Down
2 changes: 1 addition & 1 deletion inc/TaskManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TaskManager{
{
finished_tasks.resize(num_of_agents);
current_assignment.resize(num_of_agents);
for (auto & t: current_assignment)
for (int & t: current_assignment)
t = -1;
// events.resize(num_of_agents);
actual_schedule.resize(num_of_agents);
Expand Down
2 changes: 1 addition & 1 deletion inc/Tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct Task
//Task(int task_id, int location): task_id(task_id), locations({location}) {};
Task(int task_id, list<int> location, int t_revealed): task_id(task_id), t_revealed(t_revealed)
{
for (auto loc: location)
for (int loc: location)
locations.push_back(loc);
};

Expand Down
2 changes: 1 addition & 1 deletion inc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ inline DelayConfig parse_delay_config(const nlohmann::json& data)
throw std::invalid_argument("Missing required object delayConfig in the input JSON");
}

const auto& delay_json = data.at("delayConfig");
const nlohmann::json& delay_json = data.at("delayConfig");
DelayConfig config;
config.seed = read_required_json_param<unsigned int>(delay_json, "seed", "delayConfig");
config.minDelay = read_required_json_param<int>(delay_json, "minDelay", "delayConfig");
Expand Down
2 changes: 1 addition & 1 deletion python/common/opaque_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* opaque_types.h — Shared PYBIND11_MAKE_OPAQUE declarations.
*
* MUST be included in every translation unit that touches these types via pybind11.
* This prevents pybind11 from auto-converting containers to Python lists (which copies data).
* This prevents pybind11 from implicitly converting containers to Python lists (which copies data).
* Instead, Python gets a thin wrapper referencing C++ memory directly (zero-copy).
*
* Include this INSTEAD of <pybind11/stl.h> in bridge files.
Expand Down
4 changes: 2 additions & 2 deletions python/common/pyExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ vector<State> pyExecutor::process_new_plan(int sync_time_limit, Plan & plan, vec
// Python returns predicted_states (list of State).
// Since State is a registered type, we can iterate and cast.
std::vector<State> predicted;
for (auto s : result) {
for (const py::handle& s : result) {
predicted.push_back(s.cast<State>());
}
return predicted;
Expand All @@ -57,7 +57,7 @@ void pyExecutor::next_command(int exec_time_limit, std::vector<ExecutionCommand>
py::gil_scoped_acquire acquire;
py::object result = py_executor.attr("next_command")(exec_time_limit);
agent_command.clear();
for (auto cmd : result) {
for (const py::handle& cmd : result) {
agent_command.push_back(static_cast<ExecutionCommand>(cmd.cast<int>()));
}
}
4 changes: 2 additions & 2 deletions python/common/pyMAPFPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ void pyMAPFPlanner::plan(int time_limit, Plan & plan)

// Convert Python list of lists of Action (int) to C++ vector<vector<Action>>
plan.actions.clear();
for (auto agent_actions : py_actions) {
for (const py::handle& agent_actions : py_actions) {
std::vector<Action> actions_vec;
for (auto act : agent_actions) {
for (const py::handle& act : agent_actions) {
actions_vec.push_back(static_cast<Action>(act.cast<int>()));
}
plan.actions.push_back(std::move(actions_vec));
Expand Down
2 changes: 1 addition & 1 deletion python/common/pyTaskScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void pyTaskScheduler::plan(int time_limit, std::vector<int> & proposed_schedule)
py::gil_scoped_acquire acquire;
py::list result = py_scheduler.attr("plan")(time_limit);
proposed_schedule.clear();
for (auto item : result) {
for (const py::handle& item : result) {
proposed_schedule.push_back(item.cast<int>());
}
}
6 changes: 3 additions & 3 deletions src/ActionModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void collect_neighbor_agents(int agent_id, const BoxMotion& motion, StepResolveC
for (int c = c0; c <= c1; c++)
{
const int key = r * ctx.cols + c;
auto it = ctx.current_bins.find(key);
unordered_map<int, std::vector<int>>::const_iterator it = ctx.current_bins.find(key);
if (it == ctx.current_bins.end())
continue;
for (int j : it->second)
Expand Down Expand Up @@ -524,7 +524,7 @@ vector<ActionModelWithRotate::RealLocation> ActionModelWithRotate::get_real_loca

for (size_t i = 0; i < state.size(); i++)
{
const auto& s = state[i];
const State& s = state[i];
RealLocation loc;
const int row = s.location / cols;
const int col = s.location % cols;
Expand Down Expand Up @@ -632,7 +632,7 @@ void ActionModelWithRotate::sanity_check_states(const vector<State>& states)
const int nc = col + kDc[k];
if (nr < 0 || nr >= rows || nc < 0 || nc >= cols)
continue;
auto it = grid_agents.find(nr * cols + nc);
unordered_map<int, std::vector<int>>::iterator it = grid_agents.find(nr * cols + nc);
if (it == grid_agents.end())
continue;
for (int j : it->second)
Expand Down
Loading