Skip to content

Commit

Permalink
refactor(Parser): Apply parser to all struct
Browse files Browse the repository at this point in the history
  • Loading branch information
HarukiMoriarty committed Apr 9, 2024
1 parent b2bfdf3 commit 879a7b3
Show file tree
Hide file tree
Showing 16 changed files with 168 additions and 350 deletions.
166 changes: 0 additions & 166 deletions .clang-format

This file was deleted.

12 changes: 8 additions & 4 deletions calmapf/include/cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include "utils.hpp"
#include "parser.hpp"
#include <cassert>

struct Cache {
Expand All @@ -12,9 +13,6 @@ struct Cache {
std::vector<Vertices> node_coming_cargo;
std::vector<std::vector<uint>> bit_cache_get_lock;
std::vector<std::vector<uint>> bit_cache_insert_lock;
std::shared_ptr<spdlog::logger> logger;
CacheType cache_type;
std::mt19937* randomSeed;
std::vector<std::vector<bool>> is_empty;

// LRU paras
Expand All @@ -27,7 +25,13 @@ struct Cache {

// Random paras (no paras)

Cache(std::shared_ptr<spdlog::logger> _logger, CacheType _cache_type, std::mt19937* _randomSeed = 0);
// Parser
Parser* parser;

// Logger
std::shared_ptr<spdlog::logger> cache_console;

Cache(Parser* _parser);
~Cache();

/**
Expand Down
8 changes: 4 additions & 4 deletions calmapf/include/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
#pragma once
#include "utils.hpp"
#include "parser.hpp"
#include "cache.hpp"
#include <map>
#include <boost/random/mersenne_twister.hpp>
Expand All @@ -16,18 +17,17 @@ struct Graph {
std::vector<Vertices> cargo_vertices;
std::vector<Goals> goals_queue; // goals queue: length [ngoals], maximum [k] different goals in any [m] length sublist
std::vector<std::deque<int>> goals_delay; // goals delay: prevent cargos is delayed by look ahead
int delay_deadline; // delay deadline: cargo must be assigned when its delay is greater then deadline

int width; // grid width
int height; // grid height
int group; // group number
GraphType type; // graph type
std::mt19937* randomSeed;

std::shared_ptr<spdlog::logger> logger;
Parser* parser;
std::shared_ptr<spdlog::logger> graph_console;

// Instructor with cache
Graph(const std::string& filename, std::shared_ptr<spdlog::logger> _logger, GoalGenerationType goal_generation_type, std::string goal_real_file, uint goals_m, uint goals_k, uint ngoals, CacheType cache_type, int _delay_deadline, std::mt19937* _randomSeed = 0);
Graph(Parser* parser);
// Destructor
~Graph();

Expand Down
25 changes: 4 additions & 21 deletions calmapf/include/instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
* instance definition
*/
#pragma once
#include <random>

#include "graph.hpp"
#include "parser.hpp"
#include "utils.hpp"

struct Instance {
Graph graph; // graph
Config starts; // initial configuration
Config goals; // goal configuration, can be in warehouse block/cache block
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 All @@ -24,28 +23,12 @@ struct Instance {
// 4 -> cache get cargo, going back to unloading port
std::vector<uint> bit_status;

const uint nagents; // number of agents
std::vector<int> agent_group; // agents group
const uint ngoals; // number of goals
const int look_ahead;

std::shared_ptr<spdlog::logger> logger;
Parser* parser; // paras
std::shared_ptr<spdlog::logger> instance_console;

// Instructor
Instance(
const std::string& map_filename,
std::mt19937* MT,
std::shared_ptr<spdlog::logger> _logger,
GoalGenerationType goals_generation_type,
std::string goal_real_file,
CacheType cache_type,
int look_ahead = 1,
int delay_deadline = 1,
const uint _nagents = 1,
const uint _ngoals = 1,
const uint goals_m = 0,
const uint goals_k = 0
);
Instance(Parser* parser);
// Destructor
~Instance() {}

Expand Down
7 changes: 5 additions & 2 deletions calmapf/include/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct Parser {
int delay_deadline_limit;

// Goal settings
int num_goals;
uint num_goals;

std::string goals_gen_strategy_input;
GoalGenerationType goals_gen_strategy;
Expand All @@ -27,7 +27,7 @@ struct Parser {
std::string real_dist_file_path;

// Instance settings
int num_agents;
uint num_agents;

int random_seed;
std::mt19937 MT;
Expand All @@ -52,4 +52,7 @@ struct Parser {
void _post_parse();
void _check();
void _print();

// Unit test only
Parser(std::string _map_file, CacheType _cache_type);
};
Loading

0 comments on commit 879a7b3

Please sign in to comment.