Advertisement
Guest User

interscsimulator

a guest
Jul 25th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 3.81 KB | None | 0 0
  1. % Author: Eduardo Santana (efzambom@ime.usp.br)
  2.  
  3. -module(smart_city_test).
  4.  
  5. % For all facilities common to all tests:
  6. -include("test_constructs.hrl").   
  7.  
  8. -spec run() -> no_return().
  9. run() ->   
  10.  
  11.     ?test_start,
  12.    
  13.     % Use default simulation settings (50Hz, batch reproducible):
  14.     SimulationSettings = #simulation_settings{
  15.         simulation_name = "Sim-Diasca Smart City Integration Test",
  16.         tick_duration = 1,
  17.         result_specification = no_output
  18.     },
  19.  
  20.  
  21.     DeploymentSettings = #deployment_settings{
  22.         computing_hosts = localhost_only,
  23.         additional_elements_to_deploy = [ { ".", code } ],
  24.         enable_performance_tracker = false,
  25.         enable_data_logger = false
  26.     },
  27.  
  28.     % Default load balancing settings (round-robin placement heuristic):
  29.     LoadBalancingSettings = #load_balancing_settings{},
  30.  
  31.     % A deployment manager is created directly on the user node:
  32.     DeploymentManagerPid = sim_diasca:init( SimulationSettings, DeploymentSettings, LoadBalancingSettings ),
  33.  
  34.     ConfigPath = os:getenv( "CONFIG_PATH" ),
  35.    
  36.     io:format("Path: ~s", [ ConfigPath ] ),
  37.  
  38.     Config = config_parser:show( ConfigPath ),
  39.  
  40.     io:format("Trips: ~s", [ element( 4 , Config ) ] ),
  41.  
  42.     ListCars = trip_parser:show( element( 4 , Config ) ), % Read the cars from the trips.xml file
  43.  
  44.     CityGraph = map_parser:show( element( 3 , Config ) , false ), % Read the map from the map.xml file
  45.  
  46.     MetroFile = element( 5 , Config ), % Read the metro graph from the city. TODO: verify if this configurition does not exist.
  47.  
  48.     ListBuses = bus_parser:show( element( 6 , Config ) ), % Read the list of buses. TODO: verify if this configurition does not exist.
  49.  
  50.     ParkSpots = park_parser:read_csv( element( 7 , Config ) ),
  51.  
  52.     TrafficSignals = traffic_signal_parser:show( element(8, Config ) ),
  53.  
  54.     DigitalRails = digital_rails_parser:show(element(9, Config )),
  55.  
  56.     ListEdges = create_scenario:create_street_list( CityGraph ),
  57.  
  58.     { _ , Pwd } = file:get_cwd(),
  59.     OutputPath = string:concat( Pwd, "/" ),
  60.     AmqpClientPath = string:concat( Pwd, "/../deps/amqp_client"),
  61.  
  62.     LogName = string:concat( OutputPath, element( 1 , Config ) ),
  63.     Paths = [ AmqpClientPath,
  64.             string:concat( AmqpClientPath, "/ebin" ),
  65.             string:concat( AmqpClientPath, "/include/rabbit_common/ebin" )
  66.         ],
  67.     class_Actor:create_initial_actor( class_Street,  [ "Street" , ListEdges , LogName , Paths ] ),
  68.  
  69.     class_Actor:create_initial_actor( class_Metro, [ "MetroCity" , string:concat( OutputPath , MetroFile ) ] ),
  70.  
  71.     class_Actor:create_initial_actor( class_DigitalRails,  [ DigitalRails ] ),
  72.  
  73.     case element( 8 , Config ) of % verify if it is necessary to generate the city graph actor
  74.         "true" ->
  75.              class_Actor:create_initial_actor( class_City, [ "City" , { string:concat( OutputPath, element( 3 , Config ) ) } ] );
  76.         _ ->
  77.             ok
  78.     end,
  79.  
  80.     case ParkSpots of
  81.         ok ->
  82.         ok;
  83.         _ ->       
  84.         class_Actor:create_initial_actor( class_Parking , [ "Parking" , ParkSpots ] )
  85.     end,
  86.  
  87.     Names = [ "car1" , "car2" , "car3" , "car4" , "car5" , "car6" , "car7" , "car8" ],
  88.  
  89.     List = create_scenario:split_list( Names , length ( Names ) , ListCars , []  ),  
  90.  
  91.     create_scenario:spaw_proccess( List , CityGraph , DigitalRails ),
  92.  
  93.     create_scenario:collectResults( Names ),
  94.  
  95.     create_scenario:create_buses( ListBuses , CityGraph ),
  96.  
  97.     create_scenario:create_traffic_signals( TrafficSignals ),
  98.  
  99.     SimulationDuration = element( 1 , string:to_integer(element( 2 , Config ) ) ),
  100.  
  101.     DeploymentManagerPid ! { getRootTimeManager, [], self() },
  102.     RootTimeManagerPid = test_receive(),
  103.  
  104.     ?test_info_fmt( "Starting simulation, for a stop after a duration "
  105.                     "in virtual time of ~Bms.", [ SimulationDuration ] ),
  106.  
  107.     RootTimeManagerPid ! { startFor, [ SimulationDuration, self() ] },
  108.  
  109.     receive
  110.         simulation_stopped ->
  111.             ?test_info( "Simulation stopped spontaneously, "
  112.                         "specified stop tick must have been reached." )
  113.     end,
  114.  
  115.     ?test_stop.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement