Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:UCLouvain.AmbulanceSystem.Server.AmbulanceAllocator"/> class.
        /// </summary>
        /// <param name="db">Db. Do not share among threads.</param>
        public AmbulanceAtStationAllocator(MapService mapService, IDatabase db)
        {
            ambulanceRepository = new AmbulanceRepository(db);
            hospitalRepository  = new HospitalRepository(db);
            incidentRepository  = new IncidentRepository(db);

            this.mapService         = mapService;
            this.incidentsToProcess = new BlockingCollection <Incident>();

            new Thread(this.Start).Start();
        }
Ejemplo n.º 2
0
        public Cancelator(IDatabase db)
        {
            ambulanceRepository  = new AmbulanceRepository(db);
            hospitalRepository   = new HospitalRepository(db);
            incidentRepository   = new IncidentRepository(db);
            allocationRepository = new AllocationRepository(db);

            sender = new RabbitMQMessageSender();
            allocationsToProcess = new BlockingCollection <Allocation>();

            new Thread(Start).Start();
        }
Ejemplo n.º 3
0
        public ApiController()
        {
            var provider         = new PostgreSQLDatabaseProvider();
            var connectionString = ConfigurationManager.ConnectionStrings["postgres"].ConnectionString;
            var config           = DatabaseConfiguration.Build()
                                   .UsingConnectionString(connectionString)
                                   .UsingProvider(provider)
                                   .UsingDefaultMapper <ConventionMapper>();
            var db = new Database(config);

            ambulanceRepository  = new AmbulanceRepository(db);
            hospitalRepository   = new HospitalRepository(db);
            incidentRepository   = new IncidentRepository(db);
            allocationRepository = new AllocationRepository(db);
        }
Ejemplo n.º 4
0
        public Checker(IDatabaseBuildConfiguration config)
        {
            this.config = config;
            var db = new Database(config);

            ambulanceRepository     = new AmbulanceRepository(db);
            hospitalRepository      = new HospitalRepository(db);
            incidentRepository      = new IncidentRepository(db);
            allocationRepository    = new AllocationRepository(db);
            configurationRepository = new ConfigurationRepository(db);

            mapService = new MapService();

            allocator = new DefaultAmbulanceAllocator(mapService, new LoggedDatabase(config));
            configurationRepository.UpdateActiveAllocator("DefaultAmbulanceAllocator");

            mobilizator           = new AmbulanceMobilizator(new Database(config));
            trafficJamReallocator = new TrafficJamReallocator(mapService, new LoggedDatabase(config));
            cancelator            = new Cancelator(new Database(config));
        }
Ejemplo n.º 5
0
        public HomeController()
        {
            // var provider = new MonoSQLiteDatabaseProvider();
            var provider         = new PostgreSQLDatabaseProvider();
            var connectionString = ConfigurationManager.ConnectionStrings["postgres"].ConnectionString;
            var config           = DatabaseConfiguration.Build()
                                   .UsingConnectionString(connectionString)
                                   .UsingProvider(provider)
                                   .UsingDefaultMapper <ConventionMapper>();
            var db = new Database(config);

            // connection.Open();

            //logger.Info (db.ExecuteScalar<int>("select count(*) from ambulances where ambulances.ambulanceId = 'A9';"));

            ambulanceRepository  = new AmbulanceRepository(db);
            hospitalRepository   = new HospitalRepository(db);
            incidentRepository   = new IncidentRepository(db);
            allocationRepository = new AllocationRepository(db);
        }
Ejemplo n.º 6
0
        public Orchestrator(IDatabaseBuildConfiguration config)
        {
            var db = new Database(config);

            ambulanceRepository        = new AmbulanceRepository(db);
            ambulanceStationRepository = new AmbulanceStationRepository(db);
            hospitalRepository         = new HospitalRepository(db);
            incidentRepository         = new IncidentRepository(db);
            allocationRepository       = new AllocationRepository(db);

            mapService = new MapService();

            ip = new IncidentProcessor(this);
            //allocator = new AmbulanceAllocator(mapService, new LoggedDatabase(config));
            //mobilizator = new AmbulanceMobilizator(new Database (config));
            //trafficJamReallocator = new TrafficJamReallocator(mapService, new LoggedDatabase(config));
            //cancelator = new Cancelator(new Database(config));

            checker = new Checker(config);
            checker.Start();
        }
Ejemplo n.º 7
0
        public static void Main(string[] args)
        {
            //DeployAmbulanceAtStationAllocator();
            //Thread.Sleep(TimeSpan.FromSeconds(10));

            Console.WriteLine("Hello World!");
            var monitoringDelay = TimeSpan.FromSeconds(1);

            logger.Info("Connecting to database");
            var provider         = new PostgreSQLDatabaseProvider();
            var connectionString = ConfigurationManager.ConnectionStrings["postgres"].ConnectionString;

            var config = DatabaseConfiguration.Build()
                         .UsingConnectionString(connectionString)
                         .UsingProvider(provider)
                         .UsingDefaultMapper <ConventionMapper>();

            db = new Database(config);
            incidentRepository      = new IncidentRepository(db);
            ambulanceRepository     = new AmbulanceRepository(db);
            allocationRepository    = new AllocationRepository(db);
            hospitalRepository      = new HospitalRepository(db);
            configurationRepository = new ConfigurationRepository(db);
            logger.Info("Connected to database");

            logger.Info("Building KAOS model.");
            var filename = "./Models/simple.kaos";
            var parser   = new KAOSTools.Parsing.ModelBuilder();

            model = parser.Parse(File.ReadAllText(filename), filename);
            var model2 = parser.Parse(File.ReadAllText(filename), filename);

            ActiveResolutions = Enumerable.Empty <Resolution>();

            var declarations = parser.Declarations;

            logger.Info("(done)");

            logger.Info("Configuring monitors.");
            // Configure all the monitors (for all obstacles and domain properties).
            KAOSMetaModelElement[] goals     = model.Goals().ToArray();
            KAOSMetaModelElement[] obstacles = model.LeafObstacles().ToArray();
            var projection = new HashSet <string>(GetAllPredicates(goals));

            monitor = new GoalMonitor(model, goals.Union(obstacles), projection, HandleFunc,
                                      // new TimedStateInformationStorage(TimeSpan.FromMinutes(60), TimeSpan.FromMinutes(120)),
                                      monitoringDelay);
            logger.Info("(done)");

            foreach (var p in model.Predicates())
            {
                Console.WriteLine(p.FriendlyName);
            }

            // What goals and obstacles should appear in LOG
            cpsGoals     = model.Goals(x => x.CustomData.ContainsKey("log_cps"));
            cpsObstacles = model.Obstacles(x => x.CustomData.ContainsKey("log_cps"));

            // Initialize obstruction sets
            obstructionLock = new object();
            ComputeObstructionSets();

            Console.WriteLine("Waiting ...");
            Console.ReadKey();

            logger.Info("Launching monitors");
            monitor.Run(false);

            var goalMonitorProcessor = new GoalMonitorProcessor(monitor);

            csvExport = new CSVGoalExportProcessor("experiment-goal.csv", "experiment-obstacle.csv");
            // goalMonitorProcessor.AddProcessor(csvExport, monitoringDelay);

            new Timer((state) => UpdateCPS(), null, monitoringDelay, monitoringDelay);
            new Timer((state) => MonitorStep(), null, monitoringDelay, monitoringDelay);
            Thread.Sleep(TimeSpan.FromSeconds(5));
            logger.Info("Launching processors");
            //new Timer((state) => LogStatistic(), null, monitoringDelay, monitoringDelay);
            new Timer((state) => LogCSV(), null, monitoringDelay, monitoringDelay);

            // Configure optimization process.
            optimizer = new Optimizer(monitor, model2);
            new Timer((state) => Optimize(), null, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(60));

            while (true)
            {
                ;
            }
        }