Пример #1
0
 public override bool init(AGameGraph G, IGameParams prm, IPolicyGUIInputProvider gui, Dictionary <string, string> policyInput)
 {
     this.g    = (GridGameGraph)G;
     this.gm   = (GoEGameParams )prm;
     this.pgui = gui;
     foreach (Pursuer p in gm.A_P)
     {
         currentPursuersLocations[p] = new Location(Location.Type.Unset);
     }
     return(true);
 }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ep"></param>
        /// <param name="pp"></param>
        /// <param name="gameGraph"></param>
        /// <param name="input">
        /// includes policies input + optimizer specific parameters
        /// </param>
        /// <paparam name="log">
        /// slow optimizers may report progress using this log, each line will have 'LogID' appended
        /// </paparam>
        public void init(AGameGraph GameGraph,
                         IGameParams GameParams,
                         Dictionary <string, string> input)
        {
            policyInput = new Dictionary <string, string>(input);
            gameGraph   = GameGraph;
            igameParams = GameParams;

            repetitionCount =
                int.Parse(GoE.AppConstants.Algorithms.Optimizers.REPETITION_COUNT_KEY.tryRead(policyInput));

            initEx();
        }
Пример #3
0
        public static APolicyOptimizer getOptimizedPolicyInput(ParallelOptions parallelOptInner,
                                                               Dictionary <string, string> processArgs,
                                                               AGameGraph graph,
                                                               AGameProcess game,
                                                               IGameParams gameParams)
        {
            // use optimizer, if specified
            string optimizerName = AppConstants.AppArgumentKeys.POLICY_OPTIMIZER.tryRead(processArgs);

            if (optimizerName == "")
            {
                return(null);
            }

            Type policyOptimizerType = APolicyOptimizer.ChildrenByTypename[optimizerName];

            //AppSettings.WriteLogLine("invoking optimizer ...");

            APolicyOptimizer opt = (APolicyOptimizer)policyOptimizerType.GetConstructor(new Type[] { }).Invoke(new object[] { });

            opt.init(graph, gameParams, processArgs);
            opt.process(parallelOptInner);
            return(opt);
        }
Пример #4
0
        public override bool init(AGameGraph G, IGameParams prm, IPolicyGUIInputProvider pgui, Dictionary <string, string> policyParams)
        {
            IntrusionGameParams concreateParam = (IntrusionGameParams)prm;

            return(init(G, concreateParam, pgui, policyParams));
        }
Пример #5
0
 public void initParams(IGameParams param, AGameGraph GameGraph)
 {
     graph       = (EmptyEnvironment)GameGraph;
     this.Params = (AdvRoutingGameParams)param;
 }
Пример #6
0
 public bool init(AGameGraph G, IGameParams prm, APursuersPolicy initializedPursuers, IPolicyGUIInputProvider pgui, Dictionary <string, string> policyParams = null)
 {
     return(init(G, (IntrusionGameParams)prm, initializedPursuers, pgui, policyParams));
 }
Пример #7
0
 /// <summary>
 /// called once after object is constructed
 /// </summary>
 /// <param name="G"></param>
 /// <param name="prm"></param>
 /// <param name="pgui"></param>
 /// <param name="PreprocessResult">
 /// expected to include results from preProcess(), or from some other source (with the same keys e.g. a compatible optimizer)
 /// </param>
 /// <returns>
 /// false if game parameters don't allow using this policy
 /// </returns>
 public abstract bool init(AGameGraph G, IGameParams prm, IPolicyGUIInputProvider pgui,
                           Dictionary <string, string> policyParams);
Пример #8
0
        /// <summary>
        /// assumes 'processArgs' had a specific optimizer and/or policies, and uses them for the process
        /// </summary>
        /// <param name="parallelOptInner"></param>
        /// <param name="initialProcessArgs">
        /// empty values (i.e. keys with empty strings) will be ignored
        /// </param>
        /// <param name="graph"></param>
        /// <param name="optimizeInitialProcessArgs">
        /// if false, theoryOutput and optimizerOutput will not be populated
        /// and no optimizer will be used to override any of the values in optimizeInitialProcessArgs
        /// </param>
        /// <returns></returns>
        public static ProcessOutput processParams(ParallelOptions parallelOptInner,
                                                  Dictionary <string, string> initialProcessArgs,
                                                  AGameGraph graph,
                                                  bool optimizeInitialProcessArgs = true,
                                                  bool calcStdDev = true)
        {
            ProcessOutput res         = new ProcessOutput();
            var           processArgs = new Dictionary <string, string>(initialProcessArgs);

            foreach (var val in initialProcessArgs)
            {
                if (val.Value == "")
                {
                    processArgs.Remove(val.Key);
                }
            }

            // allocate game process
            string       gameType = AppConstants.AppArgumentKeys.GAME_MODEL.tryRead(processArgs);
            AGameProcess game     = Utils.ReflectionUtils.constructEmptyCtorType <AGameProcess>(gameType);

            // load game params file. processArgs may override some of the loaded values
            IGameParams gameParams = game.constructGameParams();

            gameParams.deserialize(AppConstants.AppArgumentKeys.PARAM_FILE_PATH.tryRead(processArgs), processArgs);

            APolicyOptimizer preferredOptimizer = null;// null if no optimizer specified

            if (optimizeInitialProcessArgs)
            {
                preferredOptimizer = getOptimizedPolicyInput(parallelOptInner, processArgs, graph, game, gameParams);
            }

            // if an optimizer was specified, it may have the freedom to choose from several policies, and also provide theoretical bounds *given this freedom*
            // note that the optimizer may attempt choosing policies, but can't override values in init file.
            string evadersPolicy, pursuersPolicy;

            if (preferredOptimizer != null)
            {
                res.theoryOutput = new Dictionary <string, string>(processArgs);

                // FIXME: for creating theoryOutput, if pursuers policy wasn't specificed in input params, we throw an exception.
                // this is not necessarily the correct way to do this, since theoretically the optimizer is the one that decides what pursuers policy
                // to use
                res.theoryOutput.AddRange(getPursuersPolicyTheoreticalOptimizerResult(AppConstants.AppArgumentKeys.PURSUER_POLICY.tryRead(processArgs, ""), graph, gameParams, processArgs));

                processArgs.AddRange(preferredOptimizer.optimizationOutput, false);

                res.optimizerOutput = new Dictionary <string, string>(processArgs);
                res.optimizerOutput.AddRange(preferredOptimizer.optimizationOutput);
            }

            // evadersPolicy and pursuersPolicy are extracted after the optimizer is used, since the optimizer may choose them
            evadersPolicy  = AppConstants.AppArgumentKeys.EVADER_POLICY.tryRead(processArgs);
            pursuersPolicy = AppConstants.AppArgumentKeys.PURSUER_POLICY.tryRead(processArgs);

            // if no optimizer specified, the theoretical results are calculated by the estimator (which assumes specific evaders policy and pursuers policy are given in processArgs)
            // similarly to the optimizer, the pursuer's policy can't override previous data in processArgs
            if (preferredOptimizer == null && optimizeInitialProcessArgs)
            {
                res.theoryOutput = new Dictionary <string, string>(processArgs);
                var theoreticalOptimizerRes = getPursuersPolicyTheoreticalOptimizerResult(pursuersPolicy, graph, gameParams, processArgs);
                res.theoryOutput.AddRange(theoreticalOptimizerRes);
                processArgs.AddRange(theoreticalOptimizerRes, false);
            }
            res.processOutput =
                getEstimatedResultsAverage(parallelOptInner, evadersPolicy, pursuersPolicy, gameParams, graph, processArgs, game, calcStdDev);

            return(res);
        }
Пример #9
0
        /// <summary>
        /// constructs pursuers policy object, and returns its theoretical optimizer's output
        /// </summary>
        /// <param name="pursuersPolicy"></param>
        /// <param name="graph"></param>
        /// <param name="gameParams"></param>
        /// <param name="processArgs"></param>
        /// <returns></returns>
        public static Dictionary <string, string> getPursuersPolicyTheoreticalOptimizerResult(string pursuersPolicy,
                                                                                              AGameGraph graph,
                                                                                              IGameParams gameParams,
                                                                                              Dictionary <string, string> processArgs)
        {
            // construct a dummy policy, just to make the one-time calculation of preprocess
            APursuersPolicy initPP          = ReflectionUtils.constructEmptyCtorType <APursuersPolicy>(pursuersPolicy);
            var             theoryOptimizer = initPP.constructTheoreticalOptimizer();

            if (theoryOptimizer == null)
            {
                return(new Dictionary <string, string>());
            }

            theoryOptimizer.init(graph, gameParams, processArgs);
            theoryOptimizer.process();
            return(theoryOptimizer.optimizationOutput);
        }
Пример #10
0
 //public GameProcess(GameParams param, GameGraph<Point> GameGraph)
 public void initParams(IGameParams param, AGameGraph GameGraph)
 {
     this.gr = (GameGraph <Point>)GameGraph;
     this.gm = (GoEGameParams)param;
 }