Guest User

Untitled

a guest
Jul 23rd, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. extern crate uom;
  2.  
  3. use std::fmt;
  4. use uom::si;
  5. use uom::si::f32::*;
  6.  
  7. #[derive(Debug, Clone)]
  8. struct BuildingParameters {
  9. floors: usize,
  10. interfloor_distance: Length,
  11. }
  12.  
  13. impl Default for BuildingParameters {
  14. fn default() -> Self {
  15. BuildingParameters {
  16. floors: 8,
  17. interfloor_distance: Length::new::<si::length::meter>(3.5),
  18. }
  19. }
  20. }
  21.  
  22. #[derive(Debug, Clone)]
  23. struct LiftParameters {
  24. rated_weight: Mass,
  25. rated_passengers: usize,
  26. rated_speed: Velocity,
  27. door_opening_time: Time,
  28. door_closing_time: Time,
  29. flight_time_single_floor: Time,
  30. }
  31.  
  32. impl Default for LiftParameters {
  33. fn default() -> Self {
  34. LiftParameters {
  35. rated_weight: Mass::new::<si::mass::kilogram>(5_000.0),
  36. rated_passengers: 65,
  37. rated_speed: Velocity::new::<si::velocity::meter_per_second>(1.6),
  38. door_opening_time: Time::new::<si::time::second>(1.5),
  39. door_closing_time: Time::new::<si::time::second>(1.5),
  40. flight_time_single_floor: Time::new::<si::time::second>(8.0),
  41. }
  42. }
  43. }
  44.  
  45. #[derive(Debug, Clone)]
  46. struct SimulationParameters {
  47. period: Time,
  48. slice: Time,
  49. simulations: usize,
  50. }
  51.  
  52. impl Default for SimulationParameters {
  53. fn default() -> Self {
  54. SimulationParameters {
  55. period: Time::new::<si::time::hour>(1.0),
  56. slice: Time::new::<si::time::second>(0.1),
  57. simulations: 100,
  58. }
  59. }
  60. }
  61.  
  62. impl SimulationParameters {
  63. fn total_ticks(&self) -> usize {
  64. (self.period.value / self.slice.value).ceil() as usize
  65. }
  66. }
  67.  
  68.  
  69. #[derive(Debug)]
  70. struct TrafficGenerator<'a>{
  71. sim: &'a SimulationParameters
  72. }
  73.  
  74. impl<'a> TrafficGenerator<'a> {
  75. fn new(sim: &'a SimulationParameters) -> Self {
  76. TrafficGenerator {
  77. sim
  78. }
  79. }
  80.  
  81. fn arrivals(&self) -> Vec<Vec<TrafficItem>> {
  82. (0..self.sim.total_ticks())
  83. .map(|i| self.arrivals_for_tick(i))
  84. .collect()
  85. }
  86.  
  87. fn arrivals_for_tick(&self, tick: usize) -> Vec<TrafficItem> {
  88. // TODO generate traffic pattern
  89. Vec::new()
  90. }
  91. }
  92.  
  93. #[derive(Debug, Clone)]
  94. enum TrafficItemKind {
  95. Passenger,
  96. Cargo,
  97. }
  98.  
  99. #[derive(Debug, Clone)]
  100. struct TrafficItem {
  101. id: usize,
  102. kind: TrafficItemKind,
  103. width: Length,
  104. length: Length,
  105. height: Length,
  106. weight: Mass,
  107. from_floor: usize,
  108. to_floor: usize,
  109. }
  110.  
  111. impl TrafficItem {
  112. fn transfer_time(&self) -> Time {
  113. match &self.kind {
  114. TrafficItemKind::Passenger => Time::new::<si::time::second>(2.0),
  115. TrafficItemKind::Cargo => Time::new::<si::time::second>(5.0),
  116. }
  117. }
  118. }
  119.  
  120. trait ControlStrategy {
  121. }
  122.  
  123. struct BasicControlStrategy;
  124.  
  125. impl ControlStrategy for BasicControlStrategy {
  126. // add code here
  127. }
  128.  
  129. struct AdvancedControlStrategy;
  130.  
  131. impl ControlStrategy for AdvancedControlStrategy {
  132. // add code here
  133. }
  134.  
  135. #[derive(Debug)]
  136. struct SimulationResults {
  137. }
  138.  
  139. fn main() {
  140. let b = BuildingParameters::default();
  141. let l = LiftParameters::default();
  142. let s = SimulationParameters::default();
  143. println!("{:#?}\n{:#?}\n{:#?}\ntotal_ticks: {}\n", &b, &l, &s, s.total_ticks());
  144.  
  145. let results = (0..s.simulations)
  146. .map(|_| TrafficGenerator::new(&s).arrivals())
  147. .map(|t| (
  148. run_single_simulation::<BasicControlStrategy>(&b, &l, &s, &t),
  149. run_single_simulation::<AdvancedControlStrategy>(&b, &l, &s, &t),
  150. ))
  151. .collect::<Vec<_>>();
  152.  
  153. println!("len: {}", results.len());
  154. }
  155.  
  156.  
  157. fn run_single_simulation<S: ControlStrategy>(
  158. building: &BuildingParameters,
  159. lift: &LiftParameters,
  160. sim: &SimulationParameters,
  161. traffic: &Vec<Vec<TrafficItem>>,
  162. ) -> SimulationResults {
  163. // TODO implement Simulation
  164. SimulationResults {}
  165. }
Add Comment
Please, Sign In to add comment