Patch correctif TP2
This commit is contained in:
@@ -39,27 +39,11 @@
|
||||
|
||||
namespace artis::factory {
|
||||
|
||||
struct Location {
|
||||
int _pool_id;
|
||||
unsigned int _stock_id;
|
||||
};
|
||||
|
||||
struct In {
|
||||
int _id; // -1 if global
|
||||
Location _source;
|
||||
unsigned int _quantity;
|
||||
};
|
||||
|
||||
struct Out {
|
||||
int _id; // -1 if global
|
||||
Location _destination;
|
||||
unsigned int _quantity;
|
||||
};
|
||||
|
||||
struct MachineJob {
|
||||
unsigned int _machine_id;
|
||||
std::vector<In> _ins;
|
||||
std::vector<Out> _outs;
|
||||
std::shared_ptr<Durations> _durations;
|
||||
};
|
||||
|
||||
struct PoolJob {
|
||||
@@ -69,16 +53,20 @@ struct PoolJob {
|
||||
|
||||
struct Product {
|
||||
unsigned int _id;
|
||||
std::vector<std::pair<unsigned int, unsigned int>> _components;
|
||||
std::vector<PoolJob> _pool_jobs;
|
||||
bool final;
|
||||
};
|
||||
|
||||
struct Generator {
|
||||
uint _random_seed;
|
||||
uint _min_send_speed_rate;
|
||||
uint _max_send_speed_rate;
|
||||
int _po_number;
|
||||
std::vector<unsigned int> _po_order;
|
||||
};
|
||||
|
||||
struct Stock {
|
||||
struct IntermediateStock {
|
||||
unsigned int _id;
|
||||
int _capacity; // if -1 then infinity
|
||||
};
|
||||
@@ -88,16 +76,16 @@ struct Item {
|
||||
int _quantity; // if -1 then infinity
|
||||
};
|
||||
|
||||
struct ItemStock {
|
||||
struct GlobalStock {
|
||||
unsigned int _id;
|
||||
std::vector<Item> _items;
|
||||
};
|
||||
|
||||
struct Factory {
|
||||
Generator _generator;
|
||||
std::vector<std::tuple<unsigned int, unsigned int, std::vector<std::shared_ptr<MachineParameters>>, std::vector<Stock> >> _pools;
|
||||
std::vector<std::tuple<unsigned int, unsigned int, std::vector<std::shared_ptr<MachineParameters>>, std::vector<IntermediateStock> >> _pools;
|
||||
std::map<unsigned int, Product> _products;
|
||||
std::vector<ItemStock> _stocks;
|
||||
std::vector<GlobalStock> _stocks;
|
||||
};
|
||||
|
||||
class JsonReader {
|
||||
@@ -114,6 +102,7 @@ public:
|
||||
parse_products(data["products"]);
|
||||
parse_generator(data["generator"]);
|
||||
parse_pools(data["pools"]);
|
||||
parse_product_job_durations(data["products"]);
|
||||
if (data.contains("stocks")) {
|
||||
parse_item_stocks(data["stocks"]);
|
||||
}
|
||||
@@ -123,7 +112,8 @@ private:
|
||||
void parse_generator(const nlohmann::json &data) {
|
||||
_factory._generator = Generator{data["random_seed"].get<unsigned int>(),
|
||||
data["min_send_speed_rate"].get<unsigned int>(),
|
||||
data["max_send_speed_rate"].get<unsigned int>()};
|
||||
data["max_send_speed_rate"].get<unsigned int>(),
|
||||
-1, {}};
|
||||
}
|
||||
|
||||
std::vector<In> parse_ins(const nlohmann::json &data) {
|
||||
@@ -144,8 +134,22 @@ private:
|
||||
std::vector<std::shared_ptr<MachineParameters>> machines;
|
||||
|
||||
for (const nlohmann::json &machine: data) {
|
||||
unsigned int machine_id = machine["id"].get<unsigned int>();
|
||||
unsigned int machine_type = machine["type"].get<unsigned int>();
|
||||
unsigned int capacity = machine.contains("capacity") ? machine["capacity"].get<unsigned int>() : 1;
|
||||
std::map<unsigned int, InOut> in_out;
|
||||
|
||||
for (const auto &product: _factory._products) {
|
||||
for (const auto &pool_job: product.second._pool_jobs) {
|
||||
if (pool_job._pool_id == pool_id) {
|
||||
for (const auto &machine_job: pool_job._machine_jobs) {
|
||||
if (machine_job._machine_id == machine_id) {
|
||||
in_out[product.first] = InOut{machine_job._ins, machine_job._outs};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (machine_type) {
|
||||
case PROCESSOR: {
|
||||
unsigned int load_time = machine.contains("load_time") ? machine["load_time"].get<unsigned int>() : 0;
|
||||
@@ -154,32 +158,32 @@ private:
|
||||
unsigned int unload_time = machine.contains("unload_time") ? machine["unload_time"].get<unsigned int>() : 0;
|
||||
|
||||
machines.push_back(
|
||||
std::make_shared<ProcessorParameters>(ProcessorParameters{{machine["id"].get<unsigned int>(), machine_type,
|
||||
pool_id}, load_time, processing_time,
|
||||
unload_time}));
|
||||
std::make_shared<ProcessorParameters>(ProcessorParameters{{machine_id, machine_type, pool_id, capacity},
|
||||
ProcessorDurations{{}, load_time, processing_time,
|
||||
unload_time}, in_out, {}}));
|
||||
break;
|
||||
}
|
||||
case SINK: {
|
||||
machines.push_back(std::make_shared<SinkParameters>(
|
||||
SinkParameters{{machine["id"].get<unsigned int>(), machine_type, pool_id}}));
|
||||
machines.push_back(
|
||||
std::make_shared<SinkParameters>(SinkParameters{{machine_id, machine_type, pool_id, capacity}}));
|
||||
break;
|
||||
}
|
||||
case SEPARATOR: {
|
||||
// TODO
|
||||
machines.push_back(std::make_shared<SeparatorParameters>(
|
||||
SeparatorParameters{{machine["id"].get<unsigned int>(), machine_type, pool_id}}));
|
||||
machines.push_back(
|
||||
std::make_shared<SeparatorParameters>(SeparatorParameters{{machine_id, machine_type, pool_id, capacity}}));
|
||||
break;
|
||||
}
|
||||
case COMBINER : {
|
||||
// TODO
|
||||
machines.push_back(std::make_shared<CombinerParameters>(
|
||||
CombinerParameters{{machine["id"].get<unsigned int>(), machine_type, pool_id}}));
|
||||
machines.push_back(
|
||||
std::make_shared<CombinerParameters>(CombinerParameters{{machine_id, machine_type, pool_id, capacity}}));
|
||||
break;
|
||||
}
|
||||
case CONVEYOR : {
|
||||
// TODO
|
||||
machines.push_back(std::make_shared<ConveyorParameters>(
|
||||
ConveyorParameters{{machine["id"].get<unsigned int>(), machine_type, pool_id}}));
|
||||
machines.push_back(
|
||||
std::make_shared<ConveyorParameters>(ConveyorParameters{{machine_id, machine_type, pool_id, capacity}}));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -207,7 +211,7 @@ private:
|
||||
for (const nlohmann::json &pool: data) {
|
||||
unsigned int pool_id = pool["id"].get<unsigned int>();
|
||||
unsigned int pool_type = pool["type"].get<unsigned int>();
|
||||
std::vector<Stock> stocks;
|
||||
std::vector<IntermediateStock> stocks;
|
||||
|
||||
if (pool.contains("stocks")) {
|
||||
for (const nlohmann::json &stock: pool["stocks"]) {
|
||||
@@ -224,8 +228,54 @@ private:
|
||||
void parse_products(const nlohmann::json &data) {
|
||||
for (const nlohmann::json &product: data) {
|
||||
unsigned int product_id = product["id"].get<unsigned int>();
|
||||
bool final = product.contains("final") ? product["final"].get<bool>() : true;
|
||||
std::vector<std::pair<unsigned int, unsigned int>> components;
|
||||
|
||||
_factory._products[product_id] = Product{product_id, parse_program(product["program"])};
|
||||
if (product.contains("components")) {
|
||||
for (const nlohmann::json &component: product["components"]) {
|
||||
components.emplace_back(component["id"].get<unsigned int>(), component["number"].get<unsigned int>());
|
||||
}
|
||||
}
|
||||
_factory._products[product_id] = Product{product_id, components, parse_program(product["program"]), final};
|
||||
}
|
||||
}
|
||||
|
||||
void parse_product_job_durations(const nlohmann::json &data) {
|
||||
for (const nlohmann::json &product: data) {
|
||||
unsigned int product_id = product["id"].get<unsigned int>();
|
||||
unsigned int pool_index = 0;
|
||||
|
||||
for (const nlohmann::json &pool_machine: product["program"]) {
|
||||
unsigned int pool_id = pool_machine["poolID"].get<unsigned int>();
|
||||
const auto &pool = *std::find_if(_factory._pools.cbegin(), _factory._pools.cend(),
|
||||
[pool_id](const auto &e) { return std::get<0>(e) == pool_id; });
|
||||
const auto &machines = std::get<2>(pool);
|
||||
unsigned int sequence_index = 0;
|
||||
|
||||
for (const nlohmann::json &machine: pool_machine["sequence"]) {
|
||||
if (machine.is_object()) {
|
||||
unsigned int machine_id = machine["machineID"].get<unsigned int>();
|
||||
const auto &m = *std::find_if(machines.cbegin(), machines.cend(),
|
||||
[machine_id](const auto &e) { return e->machine_id == machine_id; });
|
||||
|
||||
if (m->machine_type == PROCESSOR) {
|
||||
auto &M = (ProcessorParameters &) (*m);
|
||||
auto d = std::make_shared<ProcessorDurations>(
|
||||
ProcessorDurations{{},
|
||||
machine.contains("load_time") ? machine["load_time"].get<unsigned int>() : 0,
|
||||
machine.contains("processing_time")
|
||||
? machine["processing_time"].get<unsigned int>() : 0,
|
||||
machine.contains("unload_time") ? machine["unload_time"].get<unsigned int>() : 0
|
||||
});
|
||||
|
||||
_factory._products[product_id]._pool_jobs[pool_index]._machine_jobs[sequence_index]._durations = d;
|
||||
M.product_durations[product_id] = d;
|
||||
}
|
||||
}
|
||||
++sequence_index;
|
||||
}
|
||||
++pool_index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,9 +304,9 @@ private:
|
||||
if (machine.contains("outs")) {
|
||||
outs = parse_outs(machine["outs"]);
|
||||
}
|
||||
sequence.push_back(MachineJob{machine["machineID"].get<unsigned int>(), ins, outs});
|
||||
sequence.push_back(MachineJob{machine["machineID"].get<unsigned int>(), ins, outs, {}});
|
||||
} else {
|
||||
sequence.push_back(MachineJob{machine.get<unsigned int>(), {}, {}});
|
||||
sequence.push_back(MachineJob{machine.get<unsigned int>(), {}, {}, {}});
|
||||
}
|
||||
}
|
||||
return sequence;
|
||||
|
||||
Reference in New Issue
Block a user