docs(minimal): Create a minimal example

This is even more elementary than the starter model and is for use in the tutorial
This commit is contained in:
James P. Howard, II
2023-01-22 19:55:37 -05:00
parent f333f96bca
commit e02b339055
2 changed files with 87 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
####
# Set minimum version of CMake.
cmake_minimum_required(VERSION 3.13)
find_package(spdlog)
set(EXAMPLE_NAME "minimal")
project(${EXAMPLE_NAME} LANGUAGES CXX)
file(GLOB EXAMPLE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cc")
create_executable(
NAME ${EXAMPLE_NAME}
SOURCES ${EXAMPLE_SOURCES}
PUBLIC_DEFINITIONS USE_DOUBLE_PRECISION=1
PRIVATE_DEFINITIONS DEBUG_VERBOSE
PRIVATE_INCLUDE_PATHS ${CMAKE_SOURCE_DIR}/include
PUBLIC_LINKED_TARGETS fmt spdlog::spdlog kami::libkami
)
set_target_properties(${EXAMPLE_NAME} PROPERTIES VERSION ${VERSION_STRING})

View File

@@ -0,0 +1,65 @@
/*-
* Copyright (c) 2023 The Johns Hopkins University Applied Physics
* Laboratory LLC
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <list>
#include <map>
#include <memory>
#include <kami/agent.h>
#include <kami/kami.h>
#include <kami/model.h>
#include <kami/population.h>
#include <kami/sequential.h>
class MinimumAgent
: public kami::Agent {
public:
kami::AgentID step(std::shared_ptr<kami::Model> model) override {
return this->get_agent_id();
}
};
class MinimumModel
: public kami::Model {
public:
MinimumModel() {
_sched = std::make_shared<kami::SequentialScheduler>();
_pop = std::make_shared<kami::Population>();
for (auto i = 0; i < 10; i++) {
auto new_agent = std::make_shared<MinimumAgent>();
_pop->add_agent(new_agent);
}
}
};
int main() {
auto model = std::make_shared<MinimumModel>();
for (int i = 0; i < 10; i++)
model->step();
return 0;
}