Example #1
0
        public void TestCase()
        {
            var parser = new KAOSTools.Parsing.ModelBuilder ();

            var filename = "/Users/acailliau/Dropbox/PhD/2013/Dependent obstacles/las.kaos";
            var input = File.ReadAllText (filename);
            var model = parser.Parse (input, filename);

            Console.WriteLine ("--- [Non Satisfaction Formulas]");

            foreach (var g in model.Goals () ) {
                var node = g.GetNonSatisfactionFormula ();
                Console.WriteLine ("{0}={1}", g.FriendlyName, node.Simplify ());
            }
            Console.WriteLine ();
            foreach (var g in model.Obstacles ()) {
                Console.WriteLine ("{0}={1}", g.FriendlyName, g.GetNonSatisfactionFormula ());
            }

            Console.WriteLine ("---\n");

            Console.WriteLine ("--- [Probabilities]");

            foreach (var g in model.Goals ()) {
                Console.WriteLine ("P({0})={1}%", g.FriendlyName, Math.Round (g.ComputeProbability (), 4)*100);
            }

            Console.WriteLine ();

            foreach (var o in model.Obstacles ()) {
                Console.WriteLine ("P({0})={1}%", o.FriendlyName, Math.Round (o.ComputeProbability (), 4)*100);
            }

            Console.WriteLine ("---\n");

            model.HasObstacleWithProbability ("GPS Not Working", 0.1);
            model.HasObstacleWithProbability ("Ambulance Not in Familiar Area", 0.2);
            model.HasObstacleWithProbability ("Ambulance Lost", 0.019);
            model.HasObstacleWithProbability ("Mobilized Ambulance Not On Scene In Time", 0.0429);

            model.HasGoalWithProbability ("Achieve [Ambulance On Scene When Mobilized]", 0.9571);
            model.HasGoalWithProbability ("Achieve [Ambulance Allocated When Incident Reported]", 0.98);
            model.HasGoalWithProbability ("Achieve [Allocated Ambulance Mobilized When On Road ]", 0.98);

            model.HasGoalWithProbability ("Achieve [Mobilized By Phone When Allocated At Station]", 0.95);
            model.HasGoalWithProbability ("Achieve [Mobilized By Fax When Allocated At Station]", 0.9);

            model.HasGoalWithProbability ("Achieve [Allocated Ambulance Mobilized When At Station]", 0.995);
            model.HasGoalWithProbability ("Achieve [Ambulance Mobilized When Allocated]", 0.99);
            model.HasGoalWithProbability ("Achieve [Ambulance On Scene When Allocated]", 0.9476);
            model.HasGoalWithProbability ("Achieve [Ambulance On Scene In Time When Incident Reported]", 0.9286);
        }
Example #2
0
        protected static KAOSModel BuildModel()
        {
            // try {
            var parser = new KAOSTools.Parsing.ModelBuilder();
            var m      = parser.Parse(input, filename);

            return(m);

            // } catch (Exception e) {
            //    Console.WriteLine (e.Message);
            //    return null;
            // }
        }
Example #3
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)
            {
                ;
            }
        }