This commit is contained in:
toto
2025-09-26 11:02:27 +02:00
parent 9701e8edf2
commit 4f3043e2de
127 changed files with 51450 additions and 78 deletions

31
src/Base.cpp Normal file
View File

@@ -0,0 +1,31 @@
/**
* @file Base.cpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Base.hpp"
namespace artis::factory {
} // namespace artis::factory

69
src/Base.hpp Normal file
View File

@@ -0,0 +1,69 @@
/**
* @file Base.hpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARTIS_FACTORY_BASE_HPP
#define ARTIS_FACTORY_BASE_HPP
#include <artis-star/common/event/Bag.hpp>
#include <artis-star/common/event/ExternalEvent.hpp>
#include <artis-star/common/observer/Output.hpp>
#include <artis-star/common/observer/TimedIterator.hpp>
#include <artis-star/common/observer/View.hpp>
#include <artis-star/common/utils/Trace.hpp>
#include <artis-star/common/time/DoubleTime.hpp>
#include <artis-star/kernel/pdevs/Dynamics.hpp>
namespace artis::factory {
typedef typename artis::common::DoubleTime::type Time;
typedef typename artis::common::event::ExternalEvent<artis::common::DoubleTime> ExternalEvent;
typedef typename artis::common::event::Bag<artis::common::DoubleTime> Bag;
typedef typename artis::common::observer::View<artis::common::DoubleTime> View;
typedef typename artis::common::observer::Output<artis::common::DoubleTime, artis::common::observer::TimedIterator<artis::common::DoubleTime>> Output;
typedef typename artis::common::Coordinator<artis::common::DoubleTime> Coordinator;
typedef typename artis::common::Trace<artis::common::DoubleTime> Trace;
typedef typename artis::common::TraceElement<artis::common::DoubleTime> TraceElement;
template<class Model, class Parameters>
using Context = artis::pdevs::Context<artis::common::DoubleTime, Model, Parameters>;
template<class Model, class Parameters>
class Dynamics : public artis::pdevs::Dynamics<artis::common::DoubleTime, Model, Parameters> {
public:
Dynamics(const std::string &name, const Context<Model, Parameters> &context)
: artis::pdevs::Dynamics<artis::common::DoubleTime, Model, Parameters>(name, context) {}
~Dynamics() override = default;
void dconf(const Time &t, const Time &e, const Bag &bag) override {
this->dint(t);
this->dext(t, e, bag);
}
};
} // namespace artis::factory
#endif

19
src/CMakeLists.txt Normal file
View File

@@ -0,0 +1,19 @@
ADD_DEFINITIONS(-DWITH_TRACE)
INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src
${ARTIS_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${ARTIS_LIBRARY_DIRS})
SET(FACTORY_CORE_HPP Base.hpp Combiner.hpp Conveyor.hpp FactoryGraphManager.hpp Item.hpp ItemStock.hpp JsonReader.hpp
Machine.hpp PoolRouter.hpp Processor.hpp ProductionOrder.hpp ProductionOrderGenerator.hpp Router.hpp
Separator.hpp Sink.hpp Stock.hpp)
SET(FACTORY_CORE_CPP Base.cpp Combiner.hpp Conveyor.hpp ItemStock.cpp Machine.cpp PoolRouter.cpp Processor.cpp
ProductionOrder.cpp ProductionOrderGenerator.cpp Router.cpp Separator.cpp Sink.cpp Stock.cpp)
ADD_LIBRARY(factory_core ${FACTORY_CORE_HPP} ${FACTORY_CORE_CPP})
TARGET_LINK_LIBRARIES(factory_core ${Boost_LIBRARIES} ${ARTIS_LIBRARIES})

61
src/Combiner.cpp Normal file
View File

@@ -0,0 +1,61 @@
/**
* @file Combiner.cpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Combiner.hpp"
namespace artis::factory {
void Combiner::dint(const Time & /* t */) {
// TODO
}
void Combiner::dext(const Time & /* t */, const Time & /* e */, const Bag &bag) {
std::for_each(bag.begin(), bag.end(), [](const ExternalEvent & /* event */) {
// TODO
});
}
void Combiner::start(const Time & /* t */) {
// TODO
}
Time Combiner::ta(const Time & /* t */) const {
// TODO
return artis::common::DoubleTime::infinity;
}
Bag Combiner::lambda(const Time & /* t */) const {
Bag bag;
// TODO
return bag;
}
artis::common::event::Value Combiner::observe(const Time & /* t */, unsigned int /* index */) const {
return {};
}
} // namespace artis::factory

84
src/Combiner.hpp Normal file
View File

@@ -0,0 +1,84 @@
/**
* @file Combiner.hpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARTIS_FACTORY_COMBINER_HPP
#define ARTIS_FACTORY_COMBINER_HPP
#include "Base.hpp"
#include "Machine.hpp"
#include "ProductionOrder.hpp"
namespace artis::factory {
struct CombinerParameters : MachineParameters {
};
class Combiner : public Dynamics<Combiner, CombinerParameters> {
public:
struct inputs {
enum values {
IN
};
};
struct outputs {
enum values {
OUT
};
};
struct vars {
enum values {
};
};
Combiner(const std::string &name, const Context<Combiner, CombinerParameters> &context)
: Dynamics<Combiner, CombinerParameters>(name, context) {
input_port({inputs::IN, "in"});
output_port({outputs::OUT, "out"});
}
~Combiner() override = default;
void dint(const Time &t) override;
void dext(const Time &t, const Time &e, const Bag &bag) override;
void start(const Time &t) override;
Time ta(const Time &t) const override;
Bag lambda(const Time &t) const override;
artis::common::event::Value observe(const Time &t, unsigned int index) const override;
private:
// TODO (state)
};
} // namespace artis::factory
#endif

61
src/Conveyor.cpp Normal file
View File

@@ -0,0 +1,61 @@
/**
* @file Conveyor.cpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Conveyor.hpp"
namespace artis::factory {
void Conveyor::dint(const Time & /* t */) {
// TODO
}
void Conveyor::dext(const Time & /* t */, const Time & /* e */, const Bag &bag) {
std::for_each(bag.begin(), bag.end(), [](const ExternalEvent & /* event */) {
// TODO
});
}
void Conveyor::start(const Time & /* t */) {
// TODO
}
Time Conveyor::ta(const Time & /* t */) const {
// TODO
return artis::common::DoubleTime::infinity;
}
Bag Conveyor::lambda(const Time & /* t */) const {
Bag bag;
// TODO
return bag;
}
artis::common::event::Value Conveyor::observe(const Time & /* t */, unsigned int /* index */) const {
return {};
}
} // namespace artis::factory

84
src/Conveyor.hpp Normal file
View File

@@ -0,0 +1,84 @@
/**
* @file Conveyor.hpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARTIS_FACTORY_CONVEYOR_HPP
#define ARTIS_FACTORY_CONVEYOR_HPP
#include "Base.hpp"
#include "Machine.hpp"
#include "ProductionOrder.hpp"
namespace artis::factory {
struct ConveyorParameters : MachineParameters {
};
class Conveyor : public Dynamics<Conveyor, ConveyorParameters> {
public:
struct inputs {
enum values {
IN
};
};
struct outputs {
enum values {
OUT
};
};
struct vars {
enum values {
};
};
Conveyor(const std::string &name, const Context<Conveyor, ConveyorParameters> &context)
: Dynamics<Conveyor, ConveyorParameters>(name, context) {
input_port({inputs::IN, "in"});
output_port({outputs::OUT, "out"});
}
~Conveyor() override = default;
void dint(const Time &t) override;
void dext(const Time &t, const Time &e, const Bag &bag) override;
void start(const Time &t) override;
Time ta(const Time &t) const override;
Bag lambda(const Time &t) const override;
artis::common::event::Value observe(const Time &t, unsigned int index) const override;
private:
// TODO (state)
};
} // namespace artis::factory
#endif

145
src/FactoryGraphManager.hpp Normal file
View File

@@ -0,0 +1,145 @@
/**
* @file FactoryGraphManager.hpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARTIS_FACTORY_FACTORY_GRAPH_MANAGER_HPP
#define ARTIS_FACTORY_FACTORY_GRAPH_MANAGER_HPP
#include "Base.hpp"
#include "JsonReader.hpp"
#include "PoolRouter.hpp"
#include "Router.hpp"
#include <artis-star/kernel/pdevs/GraphManager.hpp>
namespace artis::factory {
struct FactoryGraphManagerParameters {
Factory factory;
};
class FactoryGraphManager
: public artis::pdevs::GraphManager<artis::common::DoubleTime, artis::common::NoParameters, FactoryGraphManagerParameters> {
public:
enum sub_models {
GENERATOR, ROUTER, POOL_ROUTER, MACHINE = 10000
};
FactoryGraphManager(Coordinator *coordinator, const artis::common::NoParameters &parameters,
const FactoryGraphManagerParameters &graph_parameters) :
artis::pdevs::GraphManager<artis::common::DoubleTime, artis::common::NoParameters, FactoryGraphManagerParameters>(
coordinator, parameters, graph_parameters) {
unsigned int machine_index = 0;
std::map<unsigned int, Program> programs;
for (const auto &product: graph_parameters.factory._products) {
unsigned int product_id = product.first;
Program program;
for (const auto &pool_job: product.second._pool_jobs) {
std::vector<uint8_t> machines;
for (const auto &machine_job: pool_job._machine_jobs) {
machines.push_back(machine_job._machine_id);
}
program.emplace_back((uint8_t) pool_job._pool_id, machines);
}
programs[product_id] = program;
}
ProductionOrderGeneratorParameters generator_parameters{programs,
graph_parameters.factory._generator._random_seed,
graph_parameters.factory._generator._min_send_speed_rate,
graph_parameters.factory._generator._max_send_speed_rate};
_generator = new GeneratorSimulator("G", generator_parameters);
_router = new RouterSimulator("R", {graph_parameters.factory._pools.size()});
this->add_child(ROUTER, _router);
this->add_child(GENERATOR, _generator);
for (const auto &p: graph_parameters.factory._pools) {
_pool_routers.push_back(
new PoolRouterSimulator("P_R_" + std::to_string(std::get<0>(p)),
PoolRouterParameters{std::get<1>(p), std::get<2>(p).size()}));
this->add_child(POOL_ROUTER + std::get<0>(p), _pool_routers.back());
out({_router, artis::factory::Router::outputs::OUT_P + std::get<0>(p)})
>> in({_pool_routers.back(), artis::factory::PoolRouter::inputs::IN});
out({_pool_routers.back(), artis::factory::PoolRouter::outputs::OUT})
>> in({_router, artis::factory::Router::inputs::IN_P + std::get<0>(p)});
for (const auto &m: std::get<2>(p)) {
switch (m->machine_type) {
case PROCESSOR: {
auto new_processor = new ProcessorSimulator(
"M_" + std::to_string(m->pool_id) + "_" + std::to_string(m->machine_id), (ProcessorParameters &) (*m));
_processors.push_back(new_processor);
this->add_child(MACHINE + machine_index, new_processor);
out({_pool_routers.back(), artis::factory::PoolRouter::outputs::OUT_M + m->machine_id})
>> in({new_processor, artis::factory::Processor::inputs::IN});
out({new_processor, artis::factory::Processor::outputs::OUT})
>> in({_pool_routers.back(), artis::factory::PoolRouter::inputs::IN_M + m->machine_id});
++machine_index;
break;
}
case SINK: {
// TODO
break;
}
case SEPARATOR: {
// TODO
break;
}
case COMBINER : {
// TODO
break;
}
case CONVEYOR :{
// TODO
break;
}
default: {}
}
}
}
out({_generator, artis::factory::ProductionOrderGenerator::outputs::OUT})
>> in({_router, artis::factory::Router::inputs::IN});
}
private:
typedef artis::pdevs::Simulator<artis::common::DoubleTime, artis::factory::ProductionOrderGenerator, artis::factory::ProductionOrderGeneratorParameters> GeneratorSimulator;
typedef artis::pdevs::Simulator<artis::common::DoubleTime, artis::factory::Router, artis::factory::RouterParameters> RouterSimulator;
typedef artis::pdevs::Simulator<artis::common::DoubleTime, artis::factory::PoolRouter, artis::factory::PoolRouterParameters> PoolRouterSimulator;
typedef artis::pdevs::Simulator<artis::common::DoubleTime, artis::factory::Processor, artis::factory::ProcessorParameters> ProcessorSimulator;
GeneratorSimulator *_generator;
RouterSimulator *_router;
std::vector<PoolRouterSimulator *> _pool_routers;
std::vector<ProcessorSimulator *> _processors;
};
}
#endif //ARTIS_FACTORY_FACTORY_GRAPH_MANAGER_HPP

42
src/Item.hpp Normal file
View File

@@ -0,0 +1,42 @@
/**
* @file Item.hpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARTIS_FACTORY_ITEM_HPP
#define ARTIS_FACTORY_ITEM_HPP
namespace artis::factory {
struct BaseItem {
unsigned int _id;
};
struct Item {
unsigned int _po_id;
};
}
#endif //ARTIS_FACTORY_ITEM_HPP

61
src/ItemStock.cpp Normal file
View File

@@ -0,0 +1,61 @@
/**
* @file ItemStock.cpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ItemStock.hpp"
namespace artis::factory {
void ItemStock::dint(const Time & /* t */) {
// TODO
}
void ItemStock::dext(const Time & /* t */, const Time & /* e */, const Bag &bag) {
std::for_each(bag.begin(), bag.end(), [](const ExternalEvent & /* event */) {
// TODO
});
}
void ItemStock::start(const Time & /* t */) {
// TODO
}
Time ItemStock::ta(const Time & /* t */) const {
// TODO
return artis::common::DoubleTime::infinity;
}
Bag ItemStock::lambda(const Time & /* t */) const {
Bag bag;
// TODO
return bag;
}
artis::common::event::Value ItemStock::observe(const Time & /* t */, unsigned int /* index */) const {
return {};
}
} // namespace artis::factory

83
src/ItemStock.hpp Normal file
View File

@@ -0,0 +1,83 @@
/**
* @file ItemStock.hpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARTIS_FACTORY_ITEM_STOCK_HPP
#define ARTIS_FACTORY_ITEM_STOCK_HPP
#include "Base.hpp"
#include "ProductionOrder.hpp"
namespace artis::factory {
struct ItemStockParameters {
};
class ItemStock : public Dynamics<ItemStock, ItemStockParameters> {
public:
struct inputs {
enum values {
IN
};
};
struct outputs {
enum values {
OUT
};
};
struct vars {
enum values {
};
};
ItemStock(const std::string &name, const Context<ItemStock, ItemStockParameters> &context)
: Dynamics<ItemStock, ItemStockParameters>(name, context) {
input_port({inputs::IN, "in"});
output_port({outputs::OUT, "out"});
}
~ItemStock() override = default;
void dint(const Time &t) override;
void dext(const Time &t, const Time &e, const Bag &bag) override;
void start(const Time &t) override;
Time ta(const Time &t) const override;
Bag lambda(const Time &t) const override;
artis::common::event::Value observe(const Time &t, unsigned int index) const override;
private:
// TODO (state)
};
} // namespace artis::factory
#endif

285
src/JsonReader.hpp Normal file
View File

@@ -0,0 +1,285 @@
/**
* @file Base.hpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARTIS_FACTORY_JSON_READER_HPP
#define ARTIS_FACTORY_JSON_READER_HPP
#include "Combiner.hpp"
#include "Conveyor.hpp"
#include "Machine.hpp"
#include "Processor.hpp"
#include "ProductionOrderGenerator.hpp"
#include "Separator.hpp"
#include "Sink.hpp"
#include <nlohmann/json.hpp>
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;
};
struct PoolJob {
unsigned int _pool_id;
std::vector<MachineJob> _machine_jobs;
};
struct Product {
unsigned int _id;
std::vector<PoolJob> _pool_jobs;
};
struct Generator {
uint _random_seed;
uint _min_send_speed_rate;
uint _max_send_speed_rate;
};
struct Stock {
unsigned int _id;
int _capacity; // if -1 then infinity
};
struct Item {
unsigned int _id;
int _quantity; // if -1 then infinity
};
struct ItemStock {
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::map<unsigned int, Product> _products;
std::vector<ItemStock> _stocks;
};
class JsonReader {
public:
JsonReader() = default;
const Factory &factory() const { return _factory; }
Factory &factory() { return _factory; }
void parse(const std::string &str) {
nlohmann::json data = nlohmann::json::parse(str);
parse_products(data["products"]);
parse_generator(data["generator"]);
parse_pools(data["pools"]);
if (data.contains("stocks")) {
parse_item_stocks(data["stocks"]);
}
}
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>()};
}
std::vector<In> parse_ins(const nlohmann::json &data) {
std::vector<In> ins;
for (const nlohmann::json &in: data) {
int item_id = in.contains("itemID") ? in["itemID"].get<int>() : -1;
int source_pool_id = in["source"].contains("poolID") ? in["source"]["poolID"].get<int>() : -1;
unsigned int source_stock_id = in["source"]["stockID"].get<unsigned int>();
unsigned int quantity = in.contains("quantity") ? in["quantity"].get<int>() : 1;
ins.push_back(In{item_id, Location{source_pool_id, source_stock_id}, quantity});
}
return ins;
}
std::vector<std::shared_ptr<MachineParameters>> parse_machines(const nlohmann::json &data, unsigned int pool_id) {
std::vector<std::shared_ptr<MachineParameters>> machines;
for (const nlohmann::json &machine: data) {
unsigned int machine_type = machine["type"].get<unsigned int>();
switch (machine_type) {
case PROCESSOR: {
unsigned int load_time = machine.contains("load_time") ? machine["load_time"].get<unsigned int>() : 0;
unsigned int processing_time = machine.contains("processing_time")
? machine["processing_time"].get<unsigned int>() : 0;
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}));
break;
}
case SINK: {
machines.push_back(std::make_shared<SinkParameters>(
SinkParameters{{machine["id"].get<unsigned int>(), machine_type, pool_id}}));
break;
}
case SEPARATOR: {
// TODO
machines.push_back(std::make_shared<SeparatorParameters>(
SeparatorParameters{{machine["id"].get<unsigned int>(), machine_type, pool_id}}));
break;
}
case COMBINER : {
// TODO
machines.push_back(std::make_shared<CombinerParameters>(
CombinerParameters{{machine["id"].get<unsigned int>(), machine_type, pool_id}}));
break;
}
case CONVEYOR : {
// TODO
machines.push_back(std::make_shared<ConveyorParameters>(
ConveyorParameters{{machine["id"].get<unsigned int>(), machine_type, pool_id}}));
break;
}
default: {
}
}
}
return machines;
}
std::vector<Out> parse_outs(const nlohmann::json &data) {
std::vector<Out> outs;
for (const nlohmann::json &out: data) {
int item_id = out.contains("itemID") ? out["itemID"].get<int>() : -1;
int destination_pool_id = out["destination"].contains("poolID") ? out["destination"]["poolID"].get<int>() : -1;
unsigned int destination_stock_id = out["destination"]["stockID"].get<unsigned int>();
unsigned int quantity = out.contains("quantity") ? out["quantity"].get<int>() : 1;
outs.push_back(Out{item_id, Location{destination_pool_id, destination_stock_id}, quantity});
}
return outs;
}
void parse_pools(const nlohmann::json &data) {
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;
if (pool.contains("stocks")) {
for (const nlohmann::json &stock: pool["stocks"]) {
unsigned int stock_id = stock["id"].get<unsigned int>();
int capacity = stock["capacity"].get<int>();
stocks.push_back({stock_id, capacity});
}
}
_factory._pools.emplace_back(pool_id, pool_type, parse_machines(pool["machines"], pool_id), stocks);
}
}
void parse_products(const nlohmann::json &data) {
for (const nlohmann::json &product: data) {
unsigned int product_id = product["id"].get<unsigned int>();
_factory._products[product_id] = Product{product_id, parse_program(product["program"])};
}
}
std::vector<PoolJob> parse_program(const nlohmann::json &data) {
std::vector<PoolJob> program;
for (const nlohmann::json &pool_machine: data) {
unsigned int pool_id = pool_machine["poolID"].get<unsigned int>();
program.push_back(PoolJob{pool_id, parse_sequence(pool_machine["sequence"])});
}
return program;
}
std::vector<MachineJob> parse_sequence(const nlohmann::json &data) {
std::vector<MachineJob> sequence;
for (const nlohmann::json &machine: data) {
if (machine.is_object()) {
std::vector<In> ins;
std::vector<Out> outs;
if (machine.contains("ins")) {
ins = parse_ins(machine["ins"]);
}
if (machine.contains("outs")) {
outs = parse_outs(machine["outs"]);
}
sequence.push_back(MachineJob{machine["machineID"].get<unsigned int>(), ins, outs});
} else {
sequence.push_back(MachineJob{machine.get<unsigned int>(), {}, {}});
}
}
return sequence;
}
void parse_item_stocks(const nlohmann::json &data) {
for (const nlohmann::json &stock: data) {
unsigned int stock_id = stock["id"].get<unsigned int>();
std::vector<Item> items;
for (const nlohmann::json &item: stock["items"]) {
unsigned int item_id = item["id"].get<unsigned int>();
int quantity = item["quantity"].get<int>();
items.push_back({item_id, quantity});
}
_factory._stocks.push_back({stock_id, items});
}
}
Factory _factory;
};
}
#endif //ARTIS_FACTORY_JSON_READER_HPP

31
src/Machine.cpp Normal file
View File

@@ -0,0 +1,31 @@
/**
* @file Machine.cpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Machine.hpp"
namespace artis::factory {
} // namespace artis::factory

43
src/Machine.hpp Normal file
View File

@@ -0,0 +1,43 @@
/**
* @file Machine.hpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARTIS_FACTORY_MACHINE_HPP
#define ARTIS_FACTORY_MACHINE_HPP
#include "Base.hpp"
#include "ProductionOrder.hpp"
namespace artis::factory {
struct MachineParameters {
uint machine_id;
uint machine_type;
uint pool_id;
};
} // namespace artis::factory
#endif

153
src/PoolRouter.cpp Normal file
View File

@@ -0,0 +1,153 @@
/**
* @file PoolRouter.cpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "PoolRouter.hpp"
namespace artis::factory {
void PoolRouter::dint(const Time & /* t */) {
switch (_phase) {
case Phase::INIT: {
_phase = Phase::WAIT;
break;
}
case Phase::WAIT: {
break;
}
case Phase::SEND: {
auto it = next_po();
assert(it != _pending_po.cend());
if ((*it)->is_finish()) {
_available_machines[(*it)->last_operation()->get_loc_index()] = true;
} else if ((*it)->current_operation().get_type() == CHANGE_POOL_TYPE) {
_available_machines[(*it)->previous_operation()->get_loc_index()] = true;
} else {
_available_machines[(*it)->current_operation().get_loc_index()] = false;
}
_pending_po.erase(it);
if (std::find_if(_pending_po.cbegin(), _pending_po.cend(), [this](const auto &e) {
return e->is_finish() or e->current_operation().get_type() == CHANGE_POOL_TYPE or
_available_machines[e->current_operation().get_loc_index()];
}) != _pending_po.cend()) {
_phase = Phase::SEND;
} else {
_phase = Phase::WAIT;
}
break;
}
}
}
void PoolRouter::dext(const Time &t, const Time & /* e */, const Bag &bag) {
std::for_each(bag.begin(), bag.end(), [t, this](const common::event::ExternalEvent<common::DoubleTime> &event) {
if (event.port_index() == inputs::IN) {
uint8_t *data = nullptr;
event.data()(data);
_pending_po.push_back(std::make_unique<ProductionOrder>(data, event.data().size()));
_pending_po.back()->next();
} else if (event.port_index() >= inputs::IN_M) {
uint8_t *data = nullptr;
event.data()(data);
_pending_po.push_back(std::make_unique<ProductionOrder>(data, event.data().size()));
_available_machines[event.port_index() - inputs::IN_M] = true;
_pending_po.back()->next();
}
}
);
if (std::find_if(_pending_po.cbegin(), _pending_po.cend(), [this](const auto &e) {
return e->is_finish() or e->current_operation().get_type() == CHANGE_POOL_TYPE or
_available_machines[e->current_operation().get_loc_index()];
}) != _pending_po.cend()) {
_phase = Phase::SEND;
} else {
_phase = Phase::WAIT;
}
}
void PoolRouter::start(const Time & /* t */) {
_phase = Phase::INIT;
}
Time PoolRouter::ta(const Time & /* t */) const {
switch (_phase) {
case Phase::INIT:
return 0;
case Phase::WAIT:
return artis::common::DoubleTime::infinity;
case Phase::SEND:
return 0;
}
return artis::common::DoubleTime::infinity;
}
Bag PoolRouter::lambda(const Time & /* t */) const {
Bag bag;
if (_phase == Phase::SEND) {
if (not _pending_po.empty()) {
auto it = next_po();
assert(it != _pending_po.cend());
auto po = it->get();
if (po->is_finish() or po->current_operation().get_type() == CHANGE_POOL_TYPE) {
bag.push_back(ExternalEvent(outputs::OUT, common::event::Value(po->_buffer, po->_size)));
} else if (po->current_operation().get_type() == CHANGE_MACHINE_TYPE) {
bag.push_back(ExternalEvent(outputs::OUT_M + po->current_operation().get_loc_index(),
common::event::Value(po->_buffer, po->_size)));
}
}
}
return bag;
}
artis::common::event::Value PoolRouter::observe(const Time & /* t */, unsigned int index) const {
switch (index) {
case vars::WAITING_PO_NUMBER:
return (unsigned int) _pending_po.size();
}
return {};
}
PoolRouter::ProductionOrders::const_iterator PoolRouter::next_po() const {
auto it = std::find_if(_pending_po.cbegin(), _pending_po.cend(), [](const auto &e) {
return e->is_finish() or e->current_operation().get_type() == CHANGE_POOL_TYPE;
});
if (it != _pending_po.cend()) {
return it;
} else {
return std::find_if(_pending_po.cbegin(), _pending_po.cend(),
[this](const auto &e) { return _available_machines[e->current_operation().get_loc_index()]; });
}
}
} // namespace artis::factory

123
src/PoolRouter.hpp Normal file
View File

@@ -0,0 +1,123 @@
/**
* @file PoolRouter.hpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARTIS_FACTORY_POOL_ROUTER_HPP
#define ARTIS_FACTORY_POOL_ROUTER_HPP
#include "Base.hpp"
#include "ProductionOrder.hpp"
#include <deque>
namespace artis::factory {
struct PoolRouterParameters {
uint type;
std::size_t machine_number;
};
class PoolRouter : public Dynamics<PoolRouter, PoolRouterParameters> {
public:
struct inputs {
enum values {
IN, IN_M = 1000
};
};
struct outputs {
enum values {
OUT, OUT_M = 1000
};
};
struct vars {
enum values {
WAITING_PO_NUMBER
};
};
PoolRouter(const std::string &name, const Context<PoolRouter, PoolRouterParameters> &context)
: Dynamics<PoolRouter, PoolRouterParameters>(name, context),
_parameters(context.parameters()), _available_machines(context.parameters().machine_number) {
input_port({inputs::IN, "in"});
output_port({outputs::OUT, "out"});
for (unsigned int i = 0; i < context.parameters().machine_number; ++i) {
output_port({outputs::OUT_M + i, "out_m" + std::to_string(i)});
input_port({inputs::IN_M + i, "in_m" + std::to_string(i)});
_available_machines[i] = true;
}
observables({{vars::WAITING_PO_NUMBER, "waiting_po_number"}});
}
~PoolRouter() override = default;
void dint(const Time & /* t */) override;
void dext(const Time & /* t */, const Time & /* e */, const Bag & /* bag*/) override;
void start(const Time & /* t */) override;
Time ta(const Time & /* t */) const override;
Bag lambda(const Time & /* t */) const override;
artis::common::event::Value observe(const Time &t, unsigned int index) const override;
private:
typedef std::deque<std::unique_ptr<ProductionOrder>> ProductionOrders;
ProductionOrders::const_iterator next_po() const;
struct Phase {
enum values {
INIT, WAIT, SEND
};
static std::string to_string(const values &value) {
switch (value) {
case INIT:
return "INIT";
case WAIT:
return "WAIT";
case SEND:
return "SEND";
}
return "";
}
};
// parameters
PoolRouterParameters _parameters;
// state
Phase::values _phase;
ProductionOrders _pending_po;
std::vector<bool> _available_machines;
};
} // namespace artis::factory
#endif

61
src/Processor.cpp Normal file
View File

@@ -0,0 +1,61 @@
/**
* @file Processor.cpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Processor.hpp"
namespace artis::factory {
void Processor::dint(const Time & /* t */) {
// TODO
}
void Processor::dext(const Time & /* t */, const Time & /* e */, const Bag &bag) {
std::for_each(bag.begin(), bag.end(), [](const ExternalEvent & /* event */) {
// TODO
});
}
void Processor::start(const Time & /* t */) {
// TODO
}
Time Processor::ta(const Time & /* t */) const {
// TODO
return artis::common::DoubleTime::infinity;
}
Bag Processor::lambda(const Time & /* t */) const {
Bag bag;
// TODO
return bag;
}
artis::common::event::Value Processor::observe(const Time & /* t */, unsigned int /* index */) const {
return {};
}
} // namespace artis::factory

87
src/Processor.hpp Normal file
View File

@@ -0,0 +1,87 @@
/**
* @file Processor.hpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARTIS_FACTORY_PROCESSOR_HPP
#define ARTIS_FACTORY_PROCESSOR_HPP
#include "Base.hpp"
#include "Machine.hpp"
#include "ProductionOrder.hpp"
namespace artis::factory {
struct ProcessorParameters : MachineParameters {
uint load_time;
uint processing_time;
uint unload_time;
};
class Processor : public Dynamics<Processor, ProcessorParameters> {
public:
struct inputs {
enum values {
IN
};
};
struct outputs {
enum values {
OUT
};
};
struct vars {
enum values {
};
};
Processor(const std::string &name, const Context<Processor, ProcessorParameters> &context)
: Dynamics<Processor, ProcessorParameters>(name, context) {
input_port({inputs::IN, "in"});
output_port({outputs::OUT, "out"});
}
~Processor() override = default;
void dint(const Time &t) override;
void dext(const Time &t, const Time &e, const Bag &bag) override;
void start(const Time &t) override;
Time ta(const Time &t) const override;
Bag lambda(const Time &t) const override;
artis::common::event::Value observe(const Time &t, unsigned int index) const override;
private:
// TODO (state)
};
} // namespace artis::factory
#endif

218
src/ProductionOrder.cpp Normal file
View File

@@ -0,0 +1,218 @@
/**
* @file ProductionOrder.cpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ProductionOrder.hpp"
#include <algorithm>
#include <cassert>
#include <cstring>
#include <memory>
namespace artis::factory {
void put_bits(uint8_t *buffer, ProductionOrder::Reference &reference, uint8_t data, uint8_t bit_number) {
if (8 - reference._bit_index >= bit_number) {
buffer[reference._byte_index] |= data << (8 - bit_number - reference._bit_index);
reference._bit_index += bit_number;
if (reference._bit_index == 8) {
++reference._byte_index;
reference._bit_index = 0;
}
} else {
buffer[reference._byte_index] |= data >> (bit_number - (8 - reference._bit_index));
++reference._byte_index;
reference._bit_index = bit_number - (8 - reference._bit_index);
data &= 0xFF >> (8 - reference._bit_index);
buffer[reference._byte_index] |= data << (8 - reference._bit_index);
}
}
uint8_t get_bits(uint8_t const *buffer,
const ProductionOrder::Reference &reference,
uint8_t bit_number) {
uint8_t data = 0;
if (8 - reference._bit_index >= bit_number) {
data = (uint8_t) (buffer[reference._byte_index] << reference._bit_index) >>
(8 - bit_number);
} else {
uint8_t mask = ~(uint8_t) (0xFF << (8 - reference._bit_index));
data = (uint8_t) (buffer[reference._byte_index] & mask);
data <<= bit_number - (8 - reference._bit_index);
data |= (uint8_t) (buffer[reference._byte_index + 1] >>
(8 - (bit_number - (8 - reference._bit_index))));
}
return data;
}
void ProductionOrder::Reference::operator+=(uint8_t p) {
_byte_index += (_bit_index + p) / 8;
_bit_index += p;
_bit_index %= 8;
}
ProductionOrder::ProductionOrder(uint8_t *buffer, std::size_t size)
: _buffer(nullptr), _size(size), _bsize(0), _current_operation(nullptr) {
_buffer = new uint8_t[size];
std::memcpy(_buffer, buffer, size);
_bsize = (_buffer[BIT_NUMBER_POSITION] << 8) + _buffer[BIT_NUMBER_POSITION + 1];
update_operation(_buffer[INDEX_POSITION]);
_is_finish = _buffer[INDEX_POSITION] + 1 >= _buffer[OPERATION_NUMBER_POSITION];
}
ProductionOrder::ProductionOrder(uint16_t ID, uint16_t product_ID, const Program &program) : _is_finish(false) {
Reference reference{0, 0};
std::size_t operation_number = 0;
_bsize = HEADER_SIZE * 8; // size + index + operation number
std::for_each(program.cbegin(), program.cend(),
[this, &operation_number](const PoolMachineSequence &sequence) {
_bsize +=
sequence._machines.size() * (MACHINE_SIZE + TYPE_SIZE);
_bsize += POOL_SIZE + TYPE_SIZE;
operation_number += sequence._machines.size() + 1;
});
_size = _bsize / 8 + 1;
_buffer = new uint8_t[_size];
memset(_buffer, 0, _size);
// bit number
_buffer[reference._byte_index++] = (uint8_t) (_bsize >> 8);
_buffer[reference._byte_index++] = (uint8_t) (_bsize & 0xFF);
// ID
_buffer[reference._byte_index++] = (uint8_t) (ID >> 8);
_buffer[reference._byte_index++] = (uint8_t) (ID & 0xFF);
// product ID
_buffer[reference._byte_index++] = (uint8_t) (product_ID >> 8);
_buffer[reference._byte_index++] = (uint8_t) (product_ID & 0xFF);
// index
_buffer[reference._byte_index++] = (uint8_t) (0);
assert(operation_number < 256);
// operation number
_buffer[reference._byte_index++] = (int8_t) (operation_number);
// operations {change pool ; N change machine} * M
std::for_each(program.cbegin(), program.cend(), [this, &reference](const PoolMachineSequence &sequence) {
const ChangePool &operation = sequence._pool;
assert(operation._pool_id < (1 << POOL_SIZE));
put_bits(_buffer, reference, CHANGE_POOL_TYPE, TYPE_SIZE);
put_bits(_buffer, reference, operation._pool_id, POOL_SIZE);
std::for_each(sequence._machines.cbegin(), sequence._machines.cend(),
[this, &reference](const ChangeMachine &operation) {
assert(operation._machine_id < (1 << MACHINE_SIZE));
put_bits(_buffer, reference, CHANGE_MACHINE_TYPE, TYPE_SIZE);
put_bits(_buffer, reference, operation._machine_id, MACHINE_SIZE);
});
});
// current operation
_current_operation = std::make_unique<ChangePool>(program.begin()->_pool);
}
std::unique_ptr<Operation> ProductionOrder::get_operation(uint8_t index) const {
Reference reference{HEADER_SIZE, 0};
uint8_t operation_type = get_bits(_buffer, reference, TYPE_SIZE);
reference += TYPE_SIZE;
while (index > 0) {
switch (operation_type) {
case CHANGE_POOL_TYPE: {
reference += POOL_SIZE;
break;
}
case CHANGE_MACHINE_TYPE: {
reference += MACHINE_SIZE;
break;
}
default:
assert(false);
}
operation_type = get_bits(_buffer, reference, TYPE_SIZE);
reference += TYPE_SIZE;
--index;
}
switch (operation_type) {
case CHANGE_POOL_TYPE: {
return std::make_unique<ChangePool>(get_bits(_buffer, reference, POOL_SIZE));
}
case CHANGE_MACHINE_TYPE: {
return std::make_unique<ChangeMachine>(get_bits(_buffer, reference, MACHINE_SIZE));
}
}
assert(false);
return {};
}
std::unique_ptr<Operation> ProductionOrder::last_operation() const {
return get_operation(operation_number() - 1);
}
void ProductionOrder::update_operation(uint8_t index) {
_current_operation = get_operation(index);
}
void ProductionOrder::next() {
if (_buffer[INDEX_POSITION] + 1 < _buffer[OPERATION_NUMBER_POSITION]) {
update_operation(++_buffer[INDEX_POSITION]);
} else {
_current_operation.reset(nullptr);
_is_finish = true;
}
}
std::unique_ptr<Operation> ProductionOrder::previous_operation() const {
return get_operation(_buffer[INDEX_POSITION] - 1);
}
std::string ProductionOrder::to_string() const {
std::string str = "[ ";
uint16_t ID = (_buffer[ID_POSITION] << 8) + _buffer[ID_POSITION + 1];
str += std::to_string(ID) + " ][ ";
for (uint8_t i = 0; i < _buffer[OPERATION_NUMBER_POSITION]; ++i) {
if (_buffer[INDEX_POSITION] == i) {
str += "<";
}
str += get_operation(i)->to_string();
if (_buffer[INDEX_POSITION] == i) {
str += ">";
}
str += " ";
}
str += "]";
return str;
}
} // namespace artis::factory

177
src/ProductionOrder.hpp Normal file
View File

@@ -0,0 +1,177 @@
/**
* @file ProductionOrder.hpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARTIS_FACTORY_PRODUCTION_ORDER_HPP
#define ARTIS_FACTORY_PRODUCTION_ORDER_HPP
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
namespace artis::factory {
// HEADER = [bit number (16 bits)][ID (16 bits)][Product ID (16 bits)][index (8 bits)][operation number (8 bits)]
const std::size_t POOL_SIZE = 7; // bit number
const std::size_t MACHINE_SIZE = 4; // bit number
const std::size_t TYPE_SIZE = 2; // bit number
const std::size_t HEADER_SIZE = 8; // byte number
const std::size_t BIT_NUMBER_POSITION = 0;
const std::size_t ID_POSITION = BIT_NUMBER_POSITION + 2;
const std::size_t PRODUCT_ID_POSITION = ID_POSITION + 2;
const std::size_t INDEX_POSITION = PRODUCT_ID_POSITION + 2;
const std::size_t OPERATION_NUMBER_POSITION = INDEX_POSITION + 1;
const uint8_t CHANGE_POOL_TYPE = 0x00;
const uint8_t CHANGE_MACHINE_TYPE = 0x01;
// pool type
const uint8_t FLOW_SHOP = 0x00;
const uint8_t JOB_SHOP = 0x01;
const uint8_t OPEN_SHOP = 0x02;
// machine type
const uint8_t PROCESSOR = 0x00;
const uint8_t SINK = 0x01;
const uint8_t SEPARATOR = 0x02;
const uint8_t COMBINER = 0x03;
const uint8_t CONVEYOR = 0x04;
struct Operation {
virtual uint8_t get_type() const = 0;
virtual uint8_t get_loc_index() const = 0;
virtual std::string to_string() const = 0;
virtual ~Operation() = default;
};
struct ChangePool : Operation {
uint8_t _pool_id;
explicit ChangePool(uint8_t pool_id) : _pool_id(pool_id) {}
explicit ChangePool() { _pool_id = 0; }
uint8_t get_type() const { return CHANGE_POOL_TYPE; }
uint8_t get_loc_index() const { return _pool_id; }
std::string to_string() const {
return "ChangePool(" + std::to_string(_pool_id) + ")";
}
};
struct ChangeMachine : Operation {
uint8_t _machine_id;
explicit ChangeMachine(uint8_t machine_id) : _machine_id(machine_id) {}
explicit ChangeMachine() { _machine_id = 0; }
uint8_t get_type() const { return CHANGE_MACHINE_TYPE; }
uint8_t get_loc_index() const { return _machine_id; }
std::string to_string() const {
return "ChangeMachine(" + std::to_string((int) _machine_id) + ")";
}
};
struct PoolMachineSequence {
ChangePool _pool;
std::vector<ChangeMachine> _machines;
PoolMachineSequence() = default;
PoolMachineSequence(uint8_t pool_index, const std::vector<uint8_t> &machines_indexes) {
_pool._pool_id = pool_index;
for (auto machinesIndex: machines_indexes) {
_machines.emplace_back(machinesIndex);
}
}
};
typedef std::vector<PoolMachineSequence> Program;
struct ProductionOrder {
uint8_t *_buffer;
std::size_t _size;
std::size_t _bsize;
std::unique_ptr<Operation> _current_operation;
bool _is_finish;
struct Reference {
uint8_t _byte_index;
uint8_t _bit_index;
void operator+=(uint8_t p);
};
ProductionOrder() : _buffer(nullptr), _size(0), _bsize(0), _current_operation(nullptr), _is_finish(true) {}
ProductionOrder(uint8_t *buffer, std::size_t size);
~ProductionOrder() { delete[] _buffer; }
ProductionOrder(uint16_t ID, uint16_t product_ID, const Program &program);
const Operation &current_operation() const { return *_current_operation; }
uint16_t getID() const {
return (_buffer[ID_POSITION] << 8) + _buffer[ID_POSITION + 1];
}
std::unique_ptr<Operation> get_operation(uint8_t index) const;
uint16_t get_productID() const {
return (_buffer[PRODUCT_ID_POSITION] << 8) + _buffer[PRODUCT_ID_POSITION + 1];
}
bool is_finish() const { return _is_finish; }
std::unique_ptr<Operation> last_operation() const;
void next();
std::size_t operation_index() const { return _buffer[INDEX_POSITION]; }
std::size_t operation_number() const {
return _buffer[OPERATION_NUMBER_POSITION];
}
std::unique_ptr<Operation> previous_operation() const;
std::string to_string() const;
void update_operation(uint8_t index);
};
} // namespace artis::factory
#endif

View File

@@ -0,0 +1,93 @@
/**
* @file ProductionOrderGenerator.cpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ProductionOrderGenerator.hpp"
namespace artis::factory {
void ProductionOrderGenerator::dint(const Time & /* &t */) {
switch (_phase) {
case Phase::INIT:
_phase = Phase::SEND;
break;
case Phase::SEND: {
_current_id++;
_po_counter++;
_productID = _productIDs[_distrib_product(_rng)];
_po = std::make_unique<ProductionOrder>(_current_id, _productID, _parameters.programs[_productID]);
_send_speed = _distrib_send_speed(_rng);
_phase = Phase::SEND;
break;
}
}
}
void ProductionOrderGenerator::dext(const Time & /* t */, const Time & /* e */, const Bag &bag) {
std::for_each(bag.begin(), bag.end(), [](const ExternalEvent & /* event */) {
assert(false);
});
}
void ProductionOrderGenerator::start(const Time & /* t */) {
_phase = Phase::INIT;
_po = nullptr;
_current_id = 0;
_productID = _productIDs[_distrib_product(_rng)];
_po = std::make_unique<ProductionOrder>(_current_id, _productID, _parameters.programs[_productID]);
_po_counter = 0;
_send_speed = 0; // _distrib_send_speed(_rng);
}
Time ProductionOrderGenerator::ta(const Time & /* t */) const {
switch (_phase) {
case Phase::INIT:
return 0;
case Phase::SEND:
return _send_speed;
}
return artis::common::DoubleTime::infinity;
}
Bag ProductionOrderGenerator::lambda(const Time & /* t */) const {
Bag bag;
if (_phase == Phase::SEND) {
if (_po) {
bag.push_back(ExternalEvent(outputs::OUT, common::event::Value(_po->_buffer, _po->_size)));
}
}
return bag;
}
artis::common::event::Value ProductionOrderGenerator::observe(const Time & /* t */, unsigned int index) const {
switch (index) {
case vars::TOTAL_PO_NUMBER:
return (unsigned int) _po_counter;
}
return {};
}
} // namespace artis::factory

View File

@@ -0,0 +1,131 @@
/**
* @file ProductionOrderGenerator.hpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARTIS_FACTORY_PRODUCTION_ORDER_GENERATOR_HPP
#define ARTIS_FACTORY_PRODUCTION_ORDER_GENERATOR_HPP
#include "Base.hpp"
#include "ProductionOrder.hpp"
#include <deque>
#include <map>
#include <random>
#include <vector>
namespace artis::factory {
struct ProductionOrderGeneratorParameters {
std::map<unsigned int, Program> programs;
uint random_seed;
uint min_send_speed_rate;
uint max_send_speed_rate;
};
class ProductionOrderGenerator
: public Dynamics<ProductionOrderGenerator, ProductionOrderGeneratorParameters> {
public:
struct outputs {
enum values {
OUT
};
};
struct vars {
enum values {
TOTAL_PO_NUMBER
};
};
ProductionOrderGenerator(const std::string &name,
const Context<ProductionOrderGenerator, ProductionOrderGeneratorParameters> &context)
: Dynamics<ProductionOrderGenerator, ProductionOrderGeneratorParameters>(
name, context),
_parameters(context.parameters()),
_rng(_parameters.random_seed > 0 ? std::mt19937(_parameters.random_seed) : std::mt19937(_rd())),
_distrib_product(std::uniform_int_distribution<>(0, (int) _parameters.programs.size() - 1)),
_distrib_send_speed(_parameters.min_send_speed_rate, _parameters.max_send_speed_rate) {
for (auto const &program: _parameters.programs) {
_productIDs.push_back(program.first);
}
output_port({outputs::OUT, "out"});
observables({{vars::TOTAL_PO_NUMBER, "total_po_number"}});
}
~ProductionOrderGenerator() override = default;
void dint(const Time & /* t */) override;
void dext(const Time & /* t */, const Time & /* e */, const Bag & /* bag*/) override;
void start(const Time & /* t */) override;
Time ta(const Time & /* t */) const override;
Bag lambda(const Time & /* t */) const override;
artis::common::event::Value observe(const Time &t, unsigned int index) const override;
private:
struct Phase {
enum values {
INIT, SEND
};
static std::string to_string(const values &value) {
switch (value) {
case INIT:
return "INIT";
case SEND:
return "SEND";
}
return "";
}
};
// parameters
ProductionOrderGeneratorParameters _parameters;
// state
Phase::values _phase;
std::random_device _rd;
std::mt19937 _rng;
std::uniform_int_distribution<> _distrib_product;
std::uniform_int_distribution<> _distrib_program;
std::uniform_int_distribution<> _distrib_send_speed;
std::vector<unsigned int> _productIDs;
unsigned int _productID;
std::unique_ptr<ProductionOrder> _po;
unsigned int _current_id;
std::size_t _po_counter;
unsigned int _send_speed;
};
} // namespace artis::factory
#endif

104
src/Router.cpp Normal file
View File

@@ -0,0 +1,104 @@
/**
* @file Router.cpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Router.hpp"
namespace artis::factory {
void Router::dint(const Time & /* t */) {
switch (_phase) {
case Phase::INIT: {
_phase = Phase::WAIT;
break;
}
case Phase::WAIT: {
break;
}
case Phase::SEND: {
_pending_po.pop_front();
if (not _pending_po.empty()) {
_phase = Phase::SEND;
} else {
_phase = Phase::WAIT;
}
break;
}
}
}
void Router::dext(const Time & /* t */, const Time & /* e */, const Bag &bag) {
std::for_each(bag.begin(), bag.end(), [this](const common::event::ExternalEvent<common::DoubleTime> &event) {
if (event.port_index() >= inputs::IN) {
uint8_t *data = nullptr;
event.data()(data);
_pending_po.push_back(std::make_unique<ProductionOrder>(data, event.data().size()));
_phase = Phase::SEND;
}
});
}
void Router::start(const Time & /* t */) {
_phase = Phase::INIT;
}
Time Router::ta(const Time & /* t */) const {
switch (_phase) {
case Phase::INIT:
return 0;
case Phase::WAIT:
return artis::common::DoubleTime::infinity;
case Phase::SEND:
return 0;
}
return artis::common::DoubleTime::infinity;
}
Bag Router::lambda(const Time & /* t */) const {
Bag bag;
if (_phase == Phase::SEND) {
if (not _pending_po.empty()) {
auto po = _pending_po.front().get();
if (not po->is_finish() and po->current_operation().get_type() == CHANGE_POOL_TYPE) {
bag.push_back(ExternalEvent(outputs::OUT_P + po->current_operation().get_loc_index(),
common::event::Value(po->_buffer, po->_size)));
} else if (po->is_finish()) {
bag.push_back(ExternalEvent(outputs::OUT, common::event::Value(po->_buffer, po->_size)));
} else {
assert(false);
}
}
}
return bag;
}
artis::common::event::Value Router::observe(const Time & /* t */, unsigned int /* index */) const {
return {};
}
} // namespace artis::factory

113
src/Router.hpp Normal file
View File

@@ -0,0 +1,113 @@
/**
* @file Router.hpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARTIS_FACTORY_ROUTER_HPP
#define ARTIS_FACTORY_ROUTER_HPP
#include "Base.hpp"
#include "ProductionOrder.hpp"
#include <deque>
namespace artis::factory {
struct RouterParameters {
std::size_t pool_number;
};
class Router : public Dynamics<Router, RouterParameters> {
public:
struct inputs {
enum values {
IN, IN_P = 1000
};
};
struct outputs {
enum values {
OUT, OUT_P = 1000
};
};
struct vars {
enum values {
};
};
Router(const std::string &name, const Context<Router, RouterParameters> &context)
: Dynamics<Router, RouterParameters>(name, context), _parameters(context.parameters()) {
input_port({inputs::IN, "in"});
output_port({outputs::OUT, "out"});
for (unsigned int i = 0; i < context.parameters().pool_number; ++i) {
output_port({outputs::OUT_P + i, "out_p" + std::to_string(i)});
input_port({inputs::IN_P + i, "in_p" + std::to_string(i)});
}
}
~Router() override = default;
void dint(const Time & /* t */) override;
void dext(const Time & /* t */, const Time & /* e */, const Bag & /* bag*/) override;
void start(const Time & /* t */) override;
Time ta(const Time & /* t */) const override;
Bag lambda(const Time & /* t */) const override;
artis::common::event::Value observe(const Time &t, unsigned int index) const override;
private:
struct Phase {
enum values {
INIT, WAIT, SEND
};
static std::string to_string(const values &value) {
switch (value) {
case INIT:
return "INIT";
case WAIT:
return "WAIT";
case SEND:
return "SEND";
}
return "";
}
};
// parameters
RouterParameters _parameters;
// state
Phase::values _phase;
std::deque<std::unique_ptr<ProductionOrder>> _pending_po;
};
} // namespace artis::factory
#endif

61
src/Separator.cpp Normal file
View File

@@ -0,0 +1,61 @@
/**
* @file Separator.cpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Separator.hpp"
namespace artis::factory {
void Separator::dint(const Time & /* t */) {
// TODO
}
void Separator::dext(const Time & /* t */, const Time & /* e */, const Bag &bag) {
std::for_each(bag.begin(), bag.end(), [](const ExternalEvent & /* event */) {
// TODO
});
}
void Separator::start(const Time & /* t */) {
// TODO
}
Time Separator::ta(const Time & /* t */) const {
// TODO
return artis::common::DoubleTime::infinity;
}
Bag Separator::lambda(const Time & /* t */) const {
Bag bag;
// TODO
return bag;
}
artis::common::event::Value Separator::observe(const Time & /* t */, unsigned int /* index */) const {
return {};
}
} // namespace artis::factory

84
src/Separator.hpp Normal file
View File

@@ -0,0 +1,84 @@
/**
* @file Separator.hpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARTIS_FACTORY_SEPARATOR_HPP
#define ARTIS_FACTORY_SEPARATOR_HPP
#include "Base.hpp"
#include "Machine.hpp"
#include "ProductionOrder.hpp"
namespace artis::factory {
struct SeparatorParameters : MachineParameters {
};
class Separator : public Dynamics<Separator, SeparatorParameters> {
public:
struct inputs {
enum values {
IN
};
};
struct outputs {
enum values {
OUT
};
};
struct vars {
enum values {
};
};
Separator(const std::string &name, const Context<Separator, SeparatorParameters> &context)
: Dynamics<Separator, SeparatorParameters>(name, context) {
input_port({inputs::IN, "in"});
output_port({outputs::OUT, "out"});
}
~Separator() override = default;
void dint(const Time &t) override;
void dext(const Time &t, const Time &e, const Bag &bag) override;
void start(const Time &t) override;
Time ta(const Time &t) const override;
Bag lambda(const Time &t) const override;
artis::common::event::Value observe(const Time &t, unsigned int index) const override;
private:
// TODO (state)
};
} // namespace artis::factory
#endif

61
src/Sink.cpp Normal file
View File

@@ -0,0 +1,61 @@
/**
* @file Sink.cpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Sink.hpp"
namespace artis::factory {
void Sink::dint(const Time & /* t */) {
// TODO
}
void Sink::dext(const Time & /* t */, const Time & /* e */, const Bag &bag) {
std::for_each(bag.begin(), bag.end(), [](const ExternalEvent & /* event */) {
// TODO
});
}
void Sink::start(const Time & /* t */) {
// TODO
}
Time Sink::ta(const Time & /* t */) const {
// TODO
return artis::common::DoubleTime::infinity;
}
Bag Sink::lambda(const Time & /* t */) const {
Bag bag;
// TODO
return bag;
}
artis::common::event::Value Sink::observe(const Time & /* t */, unsigned int /* index */) const {
return {};
}
} // namespace artis::factory

84
src/Sink.hpp Normal file
View File

@@ -0,0 +1,84 @@
/**
* @file Sink.hpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARTIS_FACTORY_SINK_HPP
#define ARTIS_FACTORY_SINK_HPP
#include "Base.hpp"
#include "Machine.hpp"
#include "ProductionOrder.hpp"
namespace artis::factory {
struct SinkParameters : MachineParameters {
};
class Sink : public Dynamics<Sink, SinkParameters> {
public:
struct inputs {
enum values {
IN
};
};
struct outputs {
enum values {
OUT
};
};
struct vars {
enum values {
};
};
Sink(const std::string &name, const Context<Sink, SinkParameters> &context)
: Dynamics<Sink, SinkParameters>(name, context) {
input_port({inputs::IN, "in"});
output_port({outputs::OUT, "out"});
}
~Sink() override = default;
void dint(const Time &t) override;
void dext(const Time &t, const Time &e, const Bag &bag) override;
void start(const Time &t) override;
Time ta(const Time &t) const override;
Bag lambda(const Time &t) const override;
artis::common::event::Value observe(const Time &t, unsigned int index) const override;
private:
// TODO (state)
};
} // namespace artis::factory
#endif

61
src/Stock.cpp Normal file
View File

@@ -0,0 +1,61 @@
/**
* @file Stock.cpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Stock.hpp"
namespace artis::factory {
void Stock::dint(const Time & /* t */) {
// TODO
}
void Stock::dext(const Time & /* t */, const Time & /* e */, const Bag &bag) {
std::for_each(bag.begin(), bag.end(), [](const ExternalEvent & /* event */) {
// TODO
});
}
void Stock::start(const Time & /* t */) {
// TODO
}
Time Stock::ta(const Time & /* t */) const {
// TODO
return artis::common::DoubleTime::infinity;
}
Bag Stock::lambda(const Time & /* t */) const {
Bag bag;
// TODO
return bag;
}
artis::common::event::Value Stock::observe(const Time & /* t */, unsigned int /* index */) const {
return {};
}
} // namespace artis::factory

83
src/Stock.hpp Normal file
View File

@@ -0,0 +1,83 @@
/**
* @file Stock.hpp
* @author The ARTIS Development Team
* See the AUTHORS or Authors.txt file
*/
/*
* ARTIS - the multimodeling and simulation environment
* This file is a part of the ARTIS environment
*
* Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARTIS_FACTORY_STOCK_HPP
#define ARTIS_FACTORY_STOCK_HPP
#include "Base.hpp"
#include "ProductionOrder.hpp"
namespace artis::factory {
struct StockParameters {
};
class Stock : public Dynamics<Stock, StockParameters> {
public:
struct inputs {
enum values {
IN
};
};
struct outputs {
enum values {
OUT
};
};
struct vars {
enum values {
};
};
Stock(const std::string &name, const Context<Stock, StockParameters> &context)
: Dynamics<Stock, StockParameters>(name, context) {
input_port({inputs::IN, "in"});
output_port({outputs::OUT, "out"});
}
~Stock() override = default;
void dint(const Time &t) override;
void dext(const Time &t, const Time &e, const Bag &bag) override;
void start(const Time &t) override;
Time ta(const Time &t) const override;
Bag lambda(const Time &t) const override;
artis::common::event::Value observe(const Time &t, unsigned int index) const override;
private:
// TODO (state)
};
} // namespace artis::factory
#endif