Exemplo n.º 1
0
        public void LoadlongTermMermory(String file)
        {
            NeaReader reader = new NeaReader(new StreamReader(file + ".MQ"));

            while (reader.Peek() != -1)
            {
                List <VirusMemory> memories   = new List <VirusMemory>();
                VirusBoard         startState = new VirusBoard();
                VirusBoard         endState   = new VirusBoard();
                Move   action = new Move();
                double reward;
                double significance;
                string data;

                data = reader.ReadLine();
                NeaReader r = new NeaReader(data);
                significance = double.Parse(r.ReadUntil(":"));
                while (r.Peek() != -1)
                {
                    startState.Load(r.ReadUntil(":"));
                    endState.Load(r.ReadUntil(":"));
                    action.Load(r.ReadUntil(":"));
                    reward = double.Parse(r.ReadUntil(":"));
                    memories.Add(new VirusMemory(startState, action, endState, reward));
                }


                //memory = new VirusMemory(startState, action, endState, reward);
                LongTermMemory.Add(new VirusMemoryEpisode(memories.ToArray(), significance));                //new VirusLongTermMemory(memory, significance));
            }
            reader.Close();
        }
 public PrioritySweepLearningManager(IAgent agent, LongTermMemory longTermMemory)
     : base(agent, longTermMemory)
 {
     //default thresholds
     this.MaxBackups      = 10;
     this.MinimumPriority = this.Scenario.TestsConfig.MaximalChangeThreshold;
     this.NumBackups      = new StatisticalQuantity();
 }
Exemplo n.º 3
0
    public Brain(Engine engine, FileManager fm, Player player)
    {
        p = player;
        e = engine;

        ltm = new LongTermMemory(engine, fm, player);
        stm = new ShortTermMemory();
    }
Exemplo n.º 4
0
        private void test()
        {
            Graph1 = WMH.Model.GraphGenerator.GraphGenerator.generateGraph(4);
            Graph2 = WMH.Model.GraphGenerator.GraphGenerator.generateGraph(4);

            ltm  = new LongTermMemory(10);
            tl   = new TabuList(10);
            isc  = new IterationStopCriteria(100);
            ncsc = new NoChangesStopCriteria(10);
            csc  = new CostStopCriteria(1000);
        }
Exemplo n.º 5
0
 // Use this for initialization
 void Awake()
 {
     dataPath = Application.persistentDataPath + "/playerInfo.dat";
     if (memory == null)
     {
         DontDestroyOnLoad(gameObject);
         memory = this;
     }
     else if (memory != this)
     {
         DestroyImmediate(gameObject);
     }
 }
Exemplo n.º 6
0
 private void parametersAlg(object sender, EventArgs e)
 {
     try
     {
         AlgorithmParametersView apv = new AlgorithmParametersView();
         apv.ShowDialog();
         ltm  = new LongTermMemory(apv.longTermMemory);
         tl   = new TabuList(apv.tabuList);
         isc  = new IterationStopCriteria(apv.IterationStopCrit);
         ncsc = new NoChangesStopCriteria(apv.NoChangeStopCrit);
         csc  = new CostStopCriteria(apv.CostCrit);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 7
0
        public int numberOfRecurrencesTests(int addNumbers)
        {
            LongTermMemory ltm = new LongTermMemory(10);
            Vertex         v1  = new Vertex(10, 10);
            Vertex         v2  = new Vertex(20, 20);
            Vertex         v3  = new Vertex(30, 30);
            Vertex         v4  = new Vertex(40, 40);

            Edge       edge1      = new Edge(v1, v2);
            Edge       edge2      = new Edge(v3, v4);
            EdgesAdded edgesAdded = new EdgesAdded(edge1, edge2);
            bool       b          = edgesAdded.AreEqual(edgesAdded);

            for (int i = 0; i < addNumbers; i++)
            {
                ltm.AddChange(edgesAdded);
            }
            return(ltm.numberRecurrences(edgesAdded));
        }
Exemplo n.º 8
0
        private void StartAlgorithm(int vertexNumber, int ltmLenght, int stmLenght, int endCryt, int noChangeFor, double costLessThan, int?numberOfLoop)
        {
            string currentDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string pathG1, pathG2, pathResult;

            if (numberOfLoop != null)
            {
                pathG1     = currentDir + "\\g1\\graph" + numberOfLoop;
                pathG2     = currentDir + "\\g2\\graph" + numberOfLoop;
                pathResult = currentDir + "\\result\\res" + numberOfLoop;
            }
            else
            {
                pathG1     = currentDir + "\\g1\\graph";
                pathG2     = currentDir + "\\g2\\graph";
                pathResult = currentDir + "\\result\\res";
            }
            Graph Graph1 = GraphGenerator.generateGraph(vertexNumber);

            WMH.Model.FileOperation.FileOperationGraph.SaveToFile(pathG1, Graph1.Vertexes);
            Graph Graph2 = GraphGenerator.generateGraph(vertexNumber);

            WMH.Model.FileOperation.FileOperationGraph.SaveToFile(pathG2, Graph2.Vertexes);

            LongTermMemory        ltm  = new LongTermMemory(ltmLenght);
            TabuList              tl   = new TabuList(stmLenght);
            IterationStopCriteria isc  = new IterationStopCriteria(endCryt);
            NoChangesStopCriteria ncsc = new NoChangesStopCriteria(noChangeFor);
            CostStopCriteria      csc  = new CostStopCriteria(costLessThan);

            WMH.TabuSearch.CostFinder      cf = new TabuSearch.CostFinder();
            WMH.TabuSearch.NeighbourFinder nf = new TabuSearch.NeighbourFinder(cf, ltm);
            WMH.TabuSearch.Implementation.AspirationCriteria ac = new TabuSearch.Implementation.AspirationCriteria(cf);
            WMH.TabuSearch.TabuSearch alg = new TabuSearch.TabuSearch(nf, tl, ltm, cf, ac, isc, ncsc, csc);

            System.Diagnostics.Stopwatch stopWatch = System.Diagnostics.Stopwatch.StartNew();
            IList <Edge> result = alg.FindSolution(Graph1, Graph2);

            stopWatch.Stop();


            WMH.Model.FileOperation.FileOperationResult.SaveResultToFile(result, pathResult, stopWatch);
        }
Exemplo n.º 9
0
        /*private void AddToLongTermMemory(VirusMemory memory, double significance) {
         *      if (LongTermMemory.Count < longTermMemorySize) {
         *              for (int i = 0; i <= LongTermMemory.Count; i++) {
         *                      if (i == LongTermMemory.Count) {
         *                              LongTermMemory.Add(new VirusLongTermMemory(memory, significance));
         *                              break;
         *                      }
         *                      else {
         *                              if (LongTermMemory[i].Significance < significance) {
         *                                      LongTermMemory.Insert(i, new VirusLongTermMemory(memory, significance));
         *                                      break;
         *                              }
         *                      }
         *              }
         *      }
         *      else {
         *              if (LongTermMemory[LongTermMemory.Count - 1].Significance > significance)
         *                      return;
         *
         *              for (int i = 0; i < LongTermMemory.Count; i++) {
         *                      if (LongTermMemory[i].Significance <= significance) {
         *                              LongTermMemory.Insert(i, new VirusLongTermMemory(memory, significance));
         *                              LongTermMemory.RemoveAt(LongTermMemory.Count - 1);
         *                              break;
         *                      }
         *              }
         *      }
         * }*/

        private void AddToLongTermMemory(VirusMemory[] episode, double significance)
        {
            if (LongTermMemory.Count < longTermMemorySize)
            {
                for (int i = 0; i <= LongTermMemory.Count; i++)
                {
                    if (i == LongTermMemory.Count)
                    {
                        LongTermMemory.Add(new VirusMemoryEpisode(episode, significance));
                        break;
                    }
                    else
                    {
                        if (LongTermMemory[i].Significance < significance)
                        {
                            LongTermMemory.Insert(i, new VirusMemoryEpisode(episode, significance));
                            break;
                        }
                    }
                }
            }
            else
            {
                if (LongTermMemory[LongTermMemory.Count - 1].Significance > significance)
                {
                    return;
                }

                for (int i = 0; i < LongTermMemory.Count; i++)
                {
                    if (LongTermMemory[i].Significance <= significance)
                    {
                        LongTermMemory.Insert(i, new VirusMemoryEpisode(episode, significance));
                        LongTermMemory.RemoveAt(LongTermMemory.Count - 1);
                        break;
                    }
                }
            }
        }
 public CertaintyEquivalentLearningManager(IAgent agent, LongTermMemory longTermMemory)
     : base(agent, longTermMemory)
 {
     this.MaximalChangeThreshold = this.Scenario.TestsConfig.MaximalChangeThreshold;
 }