Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate uom;
- use std::fmt;
- use uom::si;
- use uom::si::f32::*;
- #[derive(Debug, Clone)]
- struct BuildingParameters {
- floors: usize,
- interfloor_distance: Length,
- }
- impl Default for BuildingParameters {
- fn default() -> Self {
- BuildingParameters {
- floors: 8,
- interfloor_distance: Length::new::<si::length::meter>(3.5),
- }
- }
- }
- #[derive(Debug, Clone)]
- struct LiftParameters {
- rated_weight: Mass,
- rated_passengers: usize,
- rated_speed: Velocity,
- door_opening_time: Time,
- door_closing_time: Time,
- flight_time_single_floor: Time,
- }
- impl Default for LiftParameters {
- fn default() -> Self {
- LiftParameters {
- rated_weight: Mass::new::<si::mass::kilogram>(5_000.0),
- rated_passengers: 65,
- rated_speed: Velocity::new::<si::velocity::meter_per_second>(1.6),
- door_opening_time: Time::new::<si::time::second>(1.5),
- door_closing_time: Time::new::<si::time::second>(1.5),
- flight_time_single_floor: Time::new::<si::time::second>(8.0),
- }
- }
- }
- #[derive(Debug, Clone)]
- struct SimulationParameters {
- period: Time,
- slice: Time,
- simulations: usize,
- }
- impl Default for SimulationParameters {
- fn default() -> Self {
- SimulationParameters {
- period: Time::new::<si::time::hour>(1.0),
- slice: Time::new::<si::time::second>(0.1),
- simulations: 100,
- }
- }
- }
- impl SimulationParameters {
- fn total_ticks(&self) -> usize {
- (self.period.value / self.slice.value).ceil() as usize
- }
- }
- #[derive(Debug)]
- struct TrafficGenerator<'a>{
- sim: &'a SimulationParameters
- }
- impl<'a> TrafficGenerator<'a> {
- fn new(sim: &'a SimulationParameters) -> Self {
- TrafficGenerator {
- sim
- }
- }
- fn arrivals(&self) -> Vec<Vec<TrafficItem>> {
- (0..self.sim.total_ticks())
- .map(|i| self.arrivals_for_tick(i))
- .collect()
- }
- fn arrivals_for_tick(&self, tick: usize) -> Vec<TrafficItem> {
- // TODO generate traffic pattern
- Vec::new()
- }
- }
- #[derive(Debug, Clone)]
- enum TrafficItemKind {
- Passenger,
- Cargo,
- }
- #[derive(Debug, Clone)]
- struct TrafficItem {
- id: usize,
- kind: TrafficItemKind,
- width: Length,
- length: Length,
- height: Length,
- weight: Mass,
- from_floor: usize,
- to_floor: usize,
- }
- impl TrafficItem {
- fn transfer_time(&self) -> Time {
- match &self.kind {
- TrafficItemKind::Passenger => Time::new::<si::time::second>(2.0),
- TrafficItemKind::Cargo => Time::new::<si::time::second>(5.0),
- }
- }
- }
- trait ControlStrategy {
- }
- struct BasicControlStrategy;
- impl ControlStrategy for BasicControlStrategy {
- // add code here
- }
- struct AdvancedControlStrategy;
- impl ControlStrategy for AdvancedControlStrategy {
- // add code here
- }
- #[derive(Debug)]
- struct SimulationResults {
- }
- fn main() {
- let b = BuildingParameters::default();
- let l = LiftParameters::default();
- let s = SimulationParameters::default();
- println!("{:#?}\n{:#?}\n{:#?}\ntotal_ticks: {}\n", &b, &l, &s, s.total_ticks());
- let results = (0..s.simulations)
- .map(|_| TrafficGenerator::new(&s).arrivals())
- .map(|t| (
- run_single_simulation::<BasicControlStrategy>(&b, &l, &s, &t),
- run_single_simulation::<AdvancedControlStrategy>(&b, &l, &s, &t),
- ))
- .collect::<Vec<_>>();
- println!("len: {}", results.len());
- }
- fn run_single_simulation<S: ControlStrategy>(
- building: &BuildingParameters,
- lift: &LiftParameters,
- sim: &SimulationParameters,
- traffic: &Vec<Vec<TrafficItem>>,
- ) -> SimulationResults {
- // TODO implement Simulation
- SimulationResults {}
- }
Add Comment
Please, Sign In to add comment