コード例 #1
0
 public void AddSomeFinishedWork(long ID, int Piece, MappedAnswer[] results)
 {
     if (!this.OriginalTasks.PieceHasBeenWorked(ID, Piece))
     {
         this.CurrentTasks.AddCompletedWork(ID, results);
     }
 }
コード例 #2
0
 public void AddNew(long ID, MappedAnswer task)
 {
     if (task.ReduceKey == long.MaxValue)
         {
             task.ReduceKey = GetNewPlace(ID);
             this.identifier[ID].Add(task.ReduceKey, false);
         }
 }
コード例 #3
0
 public TaskInfoReduce(long ID, MappedAnswer[] task, byte[] WorkDll, string ReturnIP, int ReturnPort)
     : base(ID, WorkDll, ReturnIP, ReturnPort)
 {
     this.task = new List<MappedAnswer>();
     foreach (var item in task)
     {
         this.task.Add(item);
     }
 }
コード例 #4
0
 public void AddFinishedWork(long ID, long ReduceID, MappedAnswer[] work)
 {
     if (this.ReduceList.CheckAndSwitch(ID, ReduceID))
     {
         this.CurrentTasks.Remove(ID, ReduceID);
         this.ReduceTasks.Remove(ID, ReduceID);
         this.ReduceTasks.AddFinishedWork(ID, work);
     }
 }
コード例 #5
0
 public void AddCompletedWork(long ID, MappedAnswer[] mapping)
 {
     Monitor.Enter(tasks);
     try
     {
         if (tasks.ContainsKey(ID))
         {
             tasks[ID].AddCompletedWork(mapping);
         }
     }
     finally
     {
         Monitor.Exit(tasks);
     }
 }
 public void AddCompletedWork(MappedAnswer[] mappedAnswer)
 {
     Monitor.Enter(this.task);
     try
     {
         foreach (var item in mappedAnswer)
         {
             this.task.Add(item);
         }
     }
     finally
     {
         Monitor.Exit(this.task);
     }
 }
コード例 #7
0
        public void AddFinishedWork(long ID, MappedAnswer[] MappedData)
        {
            if (this.tasks.ContainsKey(ID))
            {
                Monitor.Enter(this.tasks);
                try
                {
                    tasks[ID].AddCompletedWork(MappedData);
                }

                finally
                {
                    Monitor.Exit(this.tasks);
                }
            }
        }
コード例 #8
0
        public MappedAnswer[] Reduce(MappedAnswer[] mappedData)
        {
            Console.WriteLine("In the reduce");
            MappedAnswer[] ma = null;
            if(null != mappedData[0] && null != mappedData[1])
            {
                List<double[]> data1 = (List<double[]>)mappedData[0].Value;
                List<Cannon> family1 = new List<Cannon>();
                foreach (var item in data1)
                {
                    family1.Add(new Cannon() { Angle = item[0], Force = item[1], minimumForce = item[2], maximumForce = item[3], minimumAngle = item[4], maximumAngle = item[5], legthToPig = item[6], wallHeight = item[9]});
                }
                List<double[]> data2 = (List<double[]>)mappedData[1].Value;
                List<Cannon> family2 = new List<Cannon>();
                foreach (var item in data2)
                {
                    family2.Add(new Cannon() { Angle = item[0], Force = item[1], minimumForce = item[2], maximumForce = item[3], minimumAngle = item[4], maximumAngle = item[5], legthToPig = item[6], wallHeight = item[9] });
                }

                List<Cannon> combinedFamily = new List<Cannon>();

                for (int i = 0; i < family1.Count(); i++)
                {
                    combinedFamily.Add(family1[i]);
                    combinedFamily.Add(family2[i]);
                }

                Family newGeneration = new Family(combinedFamily, family1[0].wallHeight);
                newGeneration.AddRandomCannons(10, 2000);
                newGeneration.fireAllCannons();
                Cannon[] answer = newGeneration.getFittest(100).ToArray();
                List<double[]> cannonConversion = new List<double[]>();

                for (int i = 0; i < answer.Length; i++)
                {
                    cannonConversion.Add(new double[] { answer[i].Angle, answer[i].Force, answer[i].minimumForce, answer[i].maximumForce, answer[i].minimumAngle, answer[i].maximumAngle, answer[i].legthToPig, answer[i].distanceFired, answer[i].fitness, answer[i].wallHeight });
                }
                Console.WriteLine("Best is " + answer[0].distanceFired + " for " + answer[0].legthToPig);
                ma = new MappedAnswer[1];
                ma[0] = new MappedAnswer("", cannonConversion);
            }
            return ma;
        }
コード例 #9
0
 public MappedAnswer[] Map(object data)
 {
     ReduceResult SomeData = (ReduceResult)data;
     double[] pigDataArray = (double[])SomeData.values;
     PigData pigData = new PigData() { distanceToPig = pigDataArray[0], generations = (int)pigDataArray[1], maximumforce = pigDataArray[2], wallheight = pigDataArray[2] };
     Family generation = new Family(pigData.wallheight);
     generation.AddRandomCannons(500, pigData.maximumforce);
     generation.fireAllCannons();
     Cannon[] answer = generation.getFittest(100).ToArray();
     List<double[]> cannonConversion = new List<double[]>();
     Console.WriteLine("Best is " + answer[0].distanceFired + " for " + pigData.distanceToPig);
     for (int i = 0; i < 100; i++)
     {
         cannonConversion.Add(new double[] { answer[i].Angle, answer[i].Force, answer[i].minimumForce, answer[i].maximumForce, answer[i].minimumAngle, answer[i].maximumAngle, answer[i].legthToPig, answer[i].distanceFired, answer[i].fitness, answer[i].wallHeight});
     }
     MappedAnswer[] ma = new MappedAnswer[1];
     ma[0] = new MappedAnswer("", cannonConversion);
     return ma;
 }
コード例 #10
0
        public MappedAnswer[] Reduce(MappedAnswer[] mappedData)
        {
            Console.WriteLine("In the Reduce!");
            double totalHits = 0;
            double totalThrows = 0;
            for (int i = 0; i < mappedData.Length; i++)
            {
                if(mappedData[i] != null)
                {
                    double hits = double.Parse(mappedData[i].Key);
                    totalHits += hits;
                    totalThrows += (double)mappedData[i].Value;
                }
            }

            Console.WriteLine("adding together hits " + totalHits + " with a total Throw of " + totalThrows);
               // double answer = total / count;
            return new MappedAnswer[] { new MappedAnswer() { Key = "" + totalHits, Value = totalThrows } };
            //Console.WriteLine("Reducing " + mappedData[0].Value);
            //int count = 0;
            //for (int i = 0; i < mappedData.Length; i++)
            //{
            //    if(mappedData[i] != null)
            //    {
            //        count += (int)mappedData[i].Value;
            //    }
            //}
            //return new MappedAnswer[] { new MappedAnswer(count.ToString(), count) };
        }
コード例 #11
0
 internal MappedAnswer MatchReduceKey(long reduceKey, MappedAnswer work)
 {
     MappedAnswer match = null;
     Monitor.Enter(this.task);
     try
     {
         for (int i = 0; i < this.task.Count() && match == null; i++)
         {
             if(task[i].ReduceKey == reduceKey && task[i] != work && !task[i].isWorked)
             {
                 match = task[i];
             }
         }
     }
     finally
     {
         Monitor.Exit(this.task);
     }
     return match;
 }
コード例 #12
0
 public void AddSomeFinishedWork(long ID, int Piece, MappedAnswer[] results)
 {
     this.TaskHandler.AddSomeFinishedWork(ID, Piece, results);
 }
コード例 #13
0
 public void AddFinishedWork(long ID, long ReduceID, MappedAnswer[] work)
 {
     this.TaskHandler.AddFinishedWork(ID, ReduceID, work);
 }
コード例 #14
0
 private void SendWork(MappedAnswer[] ma, TaskInfoCurrentlyWorking ticw, Routing Route)
 {
     ReduceList.AddNew(ticw.ID, ma[0]);
     if (ma[1] != null)
     {
         ma[1].Sent();
         ma[1].ReduceKey = ma[0].ReduceKey;
     }
     CreateAndSendMessage(ma, ticw, Route);
 }
コード例 #15
0
 private void CreateAndSendMessage(MappedAnswer[] ma, TaskInfoCurrentlyWorking ticw, Routing Route)
 {
     ReduceMessage rm = new ReduceMessage();
     rm.Port = ManagerActor.LocalPort;
     rm.ReduceDLL = ticw.WorkDLL;
     rm.TaskID = ticw.ID;
     rm.Data = ma;
     rm.ReduceID = ma[0].ReduceKey;
     new NetworkResponseActor(rm, Route.Port, Route.IP).Start();
 }
コード例 #16
0
        private bool CheckReduceIDs(MappedAnswer work, MappedAnswer work2)
        {
            bool bothOK = false;

            if((work2 != null && work.ReduceKey == long.MaxValue && work2.ReduceKey == long.MaxValue) || (work2 != null && work.ReduceKey == work2.ReduceKey))
            {
                bothOK = true;
            }
            return bothOK;
        }