Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/install-deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runs:
using: 'composite'
steps:
- name: Cache APT packages
uses: actions/cache@v4
uses: actions/cache@v5
id: cache-apt
with:
path: /var/cache/apt/archives/*.deb
Expand All @@ -20,6 +20,7 @@ runs:
sudo apt update
sudo apt install -y --download-only \
pkg-config libx11-dev libasound2-dev libudev-dev \
libwayland-dev libxkbcommon-dev \
libxcb-randr0-dev libxcb-xtest0-dev libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev \
libxcb-render0-dev libxcb-xfixes0-dev libxcb1-dev \
portaudio19-dev build-essential libpulse-dev libdbus-1-dev \
Expand All @@ -31,6 +32,7 @@ runs:
sudo apt update
sudo apt install -y \
pkg-config libx11-dev libasound2-dev libudev-dev \
libwayland-dev libxkbcommon-dev \
libxcb-randr0-dev libxcb-xtest0-dev libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev \
libxcb-render0-dev libxcb-xfixes0-dev libxcb1-dev \
portaudio19-dev build-essential libpulse-dev libdbus-1-dev \
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ This repository hosts working examples of agent-based simulations, based on the
| [Ants Foraging](antsforaging) | :heavy_check_mark: | <img src="antsforaging/ant1.gif" alt="drawing" width="200" height="200"/> |
| [Flockers](flockers) | :heavy_check_mark: | <img src="flockers/flock.gif" alt="drawing" width="200" height="200"/> |
| [ForestFire](forestfire) | :heavy_check_mark: | <img src="forestfire/ff.gif" alt="drawing" width="200" height="200"/> |
| [ForestFire_bayesian](forestfire_bayesian) | :heavy_check_mark: |
| [ForestFire_bayesian](forestfire_bayesian) | :heavy_check_mark: | :x: |
| [Schelling](schelling) | :heavy_check_mark: | <img src="schelling/schelling.gif" alt="drawing" width="200" height="200"/> |
| [Sir_bayesian](sir_bayesian) | :heavy_check_mark: |
| [Sir_ga_exploration](sir_ga_exploration) | :heavy_check_mark: |
| [Sir_bayesian](sir_bayesian) | :heavy_check_mark: | :x: |
| [Sir_ga_exploration](sir_ga_exploration) | :heavy_check_mark: | :x: |
| [Sugarscape](sugarscape) | :heavy_check_mark: | <img src="sugarscape/sugarscape.gif" alt="drawing" width="200" height="200"/> |
| [Template](template) | :heavy_check_mark: | <img src="template/template.gif" alt="drawing" width="200" height="200"/> |
| [Virus on a Network](virusnetwork) | :heavy_check_mark: | <img src="virusnetwork/virus.gif" alt="drawing" width="200" height="200"/> |
Expand Down
4 changes: 2 additions & 2 deletions antsforaging/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "antsforaging"
version = "0.3.0"
version = "0.6.0"
authors = [
"Carmine Spagnuolo <spagnuolocarmine@gmail.com>",
"Alessia Antelmi <aantelmi@unisa.it>",
Expand All @@ -18,7 +18,7 @@ readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
krabmaga = "0.5.*"
krabmaga = "0.6.*"

[features]
visualization = ["krabmaga/visualization"]
Expand Down
22 changes: 7 additions & 15 deletions antsforaging/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ use krabmaga::simulate;
// Visualization specific imports
#[cfg(any(feature = "visualization", feature = "visualization_wasm"))]
use {
crate::model::to_food_grid::ToFoodGrid, crate::model::to_home_grid::ToHomeGrid,
crate::visualization::vis_state::VisState, krabmaga::bevy::app::FixedUpdate,
krabmaga::bevy::prelude::Color, krabmaga::visualization::fields::number_grid_2d::BatchRender,
crate::model::state::ModelState, crate::model::to_food_grid::ToFoodGrid,
crate::model::to_home_grid::ToHomeGrid, crate::visualization::vis_state::VisState,
krabmaga::bevy::app::FixedUpdate, krabmaga::bevy::prelude::Color,
krabmaga::visualization::fields::number_grid_2d::BatchRender,
krabmaga::visualization::visualization::Visualization,
};

// Global imports, required in all cases
use crate::model::state::ModelState;

pub mod model;

// Constants
Expand Down Expand Up @@ -48,7 +46,7 @@ pub mod visualization;
fn main() {
let state = ModelState::new();
let mut app = Visualization::default()
.with_background_color(Color::rgb(255., 255., 255.))
.with_background_color(Color::srgb(1., 1., 1.))
.with_simulation_dimensions(WIDTH as f32, HEIGHT as f32)
.with_window_dimensions(1280., 720.)
.with_name("Ants foraging")
Expand All @@ -57,16 +55,10 @@ fn main() {
FixedUpdate,
(ToHomeGrid::batch_render, ToFoodGrid::batch_render),
);
app.run()
app.run();
}

// #[cfg(not(any(feature = "visualization", feature = "visualization_wasm")))]
// use {krabmaga::rand, krabmaga::rand::Rng};

// Main used when only the simulation should run, without any visualization.
#[cfg(not(any(feature = "visualization", feature = "visualization_wasm")))]
fn main() {
let state = ModelState::new();

let _ = simulate!(state, STEP, 10);
println!("Visualization features are not enabled. Please enable one of the visualization features to see the simulation in action.");
}
10 changes: 10 additions & 0 deletions antsforaging/src/model/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ use crate::{
};
use core::fmt;
use core::hash::{Hash, Hasher};

#[cfg(any(feature = "visualization", feature = "visualization_wasm"))]
use krabmaga::bevy::ecs as bevy_ecs;
#[cfg(any(feature = "visualization", feature = "visualization_wasm"))]
use krabmaga::bevy::prelude::Component;

use krabmaga::engine::fields::field::Field;
use krabmaga::engine::fields::sparse_object_grid_2d::SparseGrid2D;
use krabmaga::engine::location::Int2D;
Expand Down Expand Up @@ -35,6 +41,10 @@ impl fmt::Display for ItemType {
}

#[derive(Copy, Clone)]
#[cfg_attr(
any(feature = "visualization", feature = "visualization_wasm"),
derive(Component)
)]
pub struct Item {
pub id: u32,
pub value: ItemType,
Expand Down
7 changes: 2 additions & 5 deletions antsforaging/src/visualization/ant.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::model::ant::Ant;
use crate::model::state::ModelState;
use krabmaga::bevy::ecs::component::TableStorage;
use krabmaga::bevy::prelude::{Component, Quat, Transform, Visibility};
use krabmaga::bevy::prelude::{Quat, Transform, Visibility};
use krabmaga::engine::agent::Agent;
use krabmaga::engine::location::Int2D;
use krabmaga::engine::state::State;
Expand All @@ -10,9 +9,7 @@ use krabmaga::visualization::agent_render::{AgentRender, SpriteType};
pub struct AntVis {
pub id: u32,
}
impl Component for AntVis {
type Storage = TableStorage;
}

impl AgentRender for AntVis {
fn sprite(&self, _agent: &Box<dyn Agent>, _state: &Box<&dyn State>) -> SpriteType {
SpriteType::Emoji(String::from("ant"))
Expand Down
9 changes: 1 addition & 8 deletions antsforaging/src/visualization/item.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
use krabmaga::bevy::ecs::component::TableStorage;
use krabmaga::bevy::prelude::Component;

use crate::model::state::Item;

impl Component for Item {
type Storage = TableStorage;
}
// Item now derives Component in model/state.rs for Bevy 0.18 compatibility.
4 changes: 2 additions & 2 deletions antsforaging/src/visualization/vis_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::model::ant::Ant;
use crate::model::state::*;
use crate::visualization::ant::AntVis;
use krabmaga::bevy::ecs as bevy_ecs;
use krabmaga::bevy::ecs::system::Resource;
use krabmaga::bevy::prelude::Resource;

#[derive(Clone, Resource)]
pub struct VisState;
Expand Down Expand Up @@ -48,7 +48,7 @@ impl VisualizationState<ModelState> for VisState {

fn get_agent(
&self,
agent_render: &Box<dyn AgentRender>,
agent_render: &dyn AgentRender,
state: &Box<&dyn StateTrait>,
) -> Option<Box<dyn Agent>> {
let state = state.as_any().downcast_ref::<ModelState>().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions flockers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flockers"
version = "0.3.0"
version = "0.6.0"
authors = [
"Carmine Spagnuolo <spagnuolocarmine@gmail.com>",
"Alessia Antelmi <aantelmi@unisa.it>",
Expand All @@ -18,7 +18,7 @@ readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
krabmaga = "0.5.*"
krabmaga = "0.6.*"

[features]
parallel = ["krabmaga/parallel"]
Expand Down
26 changes: 8 additions & 18 deletions flockers/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
// No visualization specific imports
#[cfg(not(any(feature = "visualization", feature = "visualization_wasm")))]
use {
krabmaga::engine::schedule::Schedule,
// krabmaga::*,
krabmaga::engine::state::State,
krabmaga::simulate,
krabmaga::Info,
krabmaga::*,
std::time::Duration,
};
use {krabmaga::simulate, krabmaga::*};
// Visualization specific imports
#[cfg(any(feature = "visualization", feature = "visualization_wasm"))]
use {
crate::visualization::vis_state::VisState, krabmaga::bevy::prelude::Color,
krabmaga::visualization::visualization::Visualization,
krabmaga::engine::state::State, krabmaga::visualization::visualization::Visualization,
};

use crate::model::state::Flocker;
Expand All @@ -35,16 +27,14 @@ pub static TOROIDAL: bool = true;
// Main used when only the simulation should run, without any visualization.
#[cfg(not(any(feature = "visualization", feature = "visualization_wasm")))]
fn main() {
use krabmaga::simulate_old;

let step = 200;
let step = 1000;

let dim = (100., 100.);
let num_agents = 1000;
let dim = (1000., 1000.);
let num_agents = 10000;
let state = Flocker::new(dim, num_agents);
// let _ = simulate!(state, step, 1, Info::Normal);
// let _ = simulate!(state, step, 1);
let _ = simulate_old!(state, step, 1, krabmaga::Info::Normal);
simulate!(state, step, 1);
// let _ = simulate_old!(state, step, 1, krabmaga::Info::Normal);
}

// Main used when a visualization feature is applied.
Expand All @@ -56,7 +46,7 @@ fn main() {
Visualization::default()
.with_window_dimensions(1000., 700.)
.with_simulation_dimensions(dim.0, dim.1)
.with_background_color(Color::rgb(0., 0., 0.))
.with_background_color(Color::srgb(0., 0., 0.))
.with_name("Flockers")
.start::<VisState, Flocker>(VisState, state);
}
5 changes: 2 additions & 3 deletions flockers/src/visualization/vis_state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use krabmaga::bevy::prelude::Commands;
use krabmaga::bevy::prelude::{Commands, Resource};
use krabmaga::engine::agent::Agent;
use krabmaga::engine::location::Real2D;
use krabmaga::engine::schedule::Schedule;
Expand All @@ -12,7 +12,6 @@ use crate::model::bird::Bird;
use crate::model::state::Flocker;
use crate::visualization::bird_vis::BirdVis;
use krabmaga::bevy::ecs as bevy_ecs;
use krabmaga::bevy::ecs::system::Resource;

#[derive(Clone, Resource)]
pub struct VisState;
Expand Down Expand Up @@ -43,7 +42,7 @@ impl VisualizationState<Flocker> for VisState {

fn get_agent(
&self,
agent_render: &Box<dyn AgentRender>,
agent_render: &dyn AgentRender,
state: &Box<&dyn State>,
) -> Option<Box<dyn Agent>> {
// TODO we don't just need the agent associated to the agent render, we need the correct one so that we
Expand Down
4 changes: 2 additions & 2 deletions flockers_mpi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flockers_mpi"
version = "0.4.1"
version = "0.6.0"
authors = [
"Carmine Spagnuolo <spagnuolocarmine@gmail.com>",
"Alessia Antelmi <aantelmi@unisa.it>",
Expand All @@ -18,7 +18,7 @@ readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
krabmaga = "0.5.*"
krabmaga = "0.6.*"

[features]
distributed_mpi = ["krabmaga/distributed_mpi"]
Expand Down
4 changes: 2 additions & 2 deletions forestfire/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "forestfire"
version = "0.2.0"
version = "0.6.0"
authors = [
"Carmine Spagnuolo <spagnuolocarmine@gmail.com>",
"Alessia Antelmi <aantelmi@unisa.it>",
Expand All @@ -18,7 +18,7 @@ readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
krabmaga = "0.5.*"
krabmaga = "0.6.*"

[features]
visualization = ["krabmaga/visualization"]
Expand Down
2 changes: 1 addition & 1 deletion forestfire/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn main() {
let mut app = Visualization::default()
.with_simulation_dimensions(state.dim.0 as f32, state.dim.1 as f32)
.with_window_dimensions(1000., 720.)
.with_background_color(Color::BLACK)
.with_background_color(Color::srgb(0., 0., 0.))
.with_name("Forest Fire Model")
.setup::<ForestVis, Forest>(ForestVis, state);
app.add_systems(FixedUpdate, DenseGrid2D::<Tree>::render);
Expand Down
8 changes: 8 additions & 0 deletions forestfire/src/model/forest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use crate::model::spread::Spread;
use core::fmt;
#[cfg(any(feature = "visualization", feature = "visualization_wasm"))]
use krabmaga::bevy::ecs as bevy_ecs;
#[cfg(any(feature = "visualization", feature = "visualization_wasm"))]
use krabmaga::bevy::prelude::Component;
use krabmaga::engine::fields::dense_object_grid_2d::DenseGrid2D;
use krabmaga::engine::fields::field::Field;
use krabmaga::engine::location::Int2D;
Expand Down Expand Up @@ -29,6 +33,10 @@ impl fmt::Display for Status {
}

#[derive(Copy, Clone)]
#[cfg_attr(
any(feature = "visualization", feature = "visualization_wasm"),
derive(Component)
)]
pub struct Tree {
pub id: i32,
pub status: Status,
Expand Down
6 changes: 0 additions & 6 deletions forestfire/src/visualization/custom_systems.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
use crate::model::forest::*;
use krabmaga::bevy::ecs::component::TableStorage;
use krabmaga::bevy::prelude::Component;
use krabmaga::engine::fields::dense_object_grid_2d::DenseGrid2D;
use krabmaga::engine::fields::sparse_object_grid_2d::SparseGrid2D;
use krabmaga::engine::location::Int2D;
use krabmaga::visualization::fields::object_grid_2d::RenderObjectGrid2D;

impl Component for Tree {
type Storage = TableStorage;
}

impl RenderObjectGrid2D<Forest, Tree> for DenseGrid2D<Tree> {
fn fetch_sparse_grid(_state: &Forest) -> Option<&SparseGrid2D<Tree>> {
None
Expand Down
4 changes: 2 additions & 2 deletions forestfire/src/visualization/forest_vis.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::model::forest::Forest;
use crate::Tree;
use krabmaga::bevy::ecs as bevy_ecs;
use krabmaga::bevy::ecs::system::Resource;
use krabmaga::bevy::prelude::Commands;
use krabmaga::bevy::prelude::Resource;
use krabmaga::engine::agent::Agent;
use krabmaga::engine::fields::dense_object_grid_2d::DenseGrid2D;
use krabmaga::engine::fields::field::Field;
Expand Down Expand Up @@ -49,7 +49,7 @@ impl VisualizationState<Forest> for ForestVis {

fn get_agent(
&self,
_agent_render: &Box<dyn AgentRender>,
_agent_render: &dyn AgentRender,
_state: &Box<&dyn State>,
) -> Option<Box<dyn Agent>> {
None
Expand Down
4 changes: 2 additions & 2 deletions forestfire_bayesian/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "forestfire_bayesian"
version = "0.2.0"
version = "0.6.0"
authors = [
"Carmine Spagnuolo <spagnuolocarmine@gmail.com>",
"Alessia Antelmi <aantelmi@unisa.it>",
Expand All @@ -18,7 +18,7 @@ readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
krabmaga = "0.5.*"
krabmaga = "0.6.*"

[features]
bayesian = ["krabmaga/bayesian"]
4 changes: 0 additions & 4 deletions forestfire_bayesian/src/visualization/custom_systems.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use krabmaga::bevy::ecs::component::TableStorage;
use krabmaga::bevy::prelude::Component;
use crate::model::forest::*;
use krabmaga::engine::fields::dense_object_grid_2d::DenseGrid2D;
use krabmaga::engine::fields::sparse_object_grid_2d::SparseGrid2D;
use krabmaga::engine::location::Int2D;
use krabmaga::visualization::fields::object_grid_2d::RenderObjectGrid2D;

impl Component for Tree { type Storage = TableStorage; }

impl RenderObjectGrid2D<Forest, Tree> for DenseGrid2D<Tree> {
fn fetch_sparse_grid(_state: &Forest) -> Option<&SparseGrid2D<Tree>> {
None
Expand Down
Loading
Loading