Ejemplo n.º 1
0
        public void NextGenClick(object sender, RoutedEventArgs routedEventArgs)
        {
            Individu[] newPop = new Individu[Population.MAXINDIVIDUS];

            for (int i = 0; i < Population.MAXINDIVIDUS; i++)
            {
                int      rnd = MidiComposer.GetRandom(0, 100);
                Individu newInd;

                if (rnd < Population.CROSSOVER)
                {
                    Individu parent1 = SelectParent();
                    Individu parent2 = SelectParent();

                    newInd = new Individu(parent1, parent2);
                }
                else
                {
                    Individu parent = SelectParent();

                    newInd = new Individu(parent);
                }

                newInd.Mutate();
                newPop[i] = newInd;
            }

            Generation mg = new Generation(newPop);

            Survival();
            Gens.Add(mg);
            //populations[nbPopulation] = new Population(nbPopulation + 1, newPop);
        }
Ejemplo n.º 2
0
        public void Generate(int countgens, int len, int min, int max)
        {
            var r = new Random();

            for (var i = 0; i < countgens; i++)
            {
                var temp   = r.Next(min, max);
                var result = DecToBin(temp - min, len);
                Gens.Add(result);
            }
        }
Ejemplo n.º 3
0
        public void SavePopulation(string fileName)
        {
            Generation[]  lol        = Gens.ToArray();
            XmlSerializer serializer = new XmlSerializer(lol.GetType());

            File.Delete(fileName);

            using (StreamWriter writer = new StreamWriter(fileName))
            {
                serializer.Serialize(writer, lol);
            }
            SaveFileExists = true;
        }
Ejemplo n.º 4
0
        public void CreateClick(object sender, RoutedEventArgs routedEventArgs)
        {
            Individu[] individus = new Individu[Population.MAXINDIVIDUS];

            for (int i = 0; i < Population.MAXINDIVIDUS; i++)
            {
                individus[i] = new Individu();
            }


            Generation gen = new Generation(individus);

            Gens.Add(gen);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Launch an OpenFileDialog an populate the TASMovieInputCollection object
        /// according to the type of movie file that's selected
        /// </summary>
        private string loadMovie(ref TASMovieInputCollection location)
        {
            openDlg        = new OpenFileDialog();
            openDlg.Filter = TAS_FILTER;
            openDlg.ShowDialog();
            string filename = openDlg.FileName;

            openDlg.Dispose();

            if (filename.Length == 0)
            {
                return(null);
            }

            TASMovie movie = new TASMovie();

            location        = new TASMovieInputCollection();
            location.Format = IsValid(filename);

            // load the movie object up with the correct format
            switch (location.Format)
            {
            case MovieType.SMV: movie = new SNES9x(filename); break;

            case MovieType.FCM: movie = new FCEU(filename); break;

            case MovieType.GMV: movie = new Gens(filename); break;

            case MovieType.FMV: movie = new Famtasia(filename); break;

            case MovieType.VBM: movie = new VisualBoyAdvance(filename); break;

            case MovieType.M64: movie = new Mupen64(filename); break;

            case MovieType.MMV: movie = new Dega(filename); break;

            case MovieType.PXM: movie = new PCSX(filename); break;      // shares with PJM

            case MovieType.PJM: movie = new PCSX(filename); break;      // shares with PXM
            }
            location.Input       = movie.Input.FrameData;
            location.Controllers = movie.Input.ControllerCount;

            return(filename);
        }
Ejemplo n.º 6
0
        public void LoadPopulation(string filename)
        {
            XmlTextReader xr = new XmlTextReader(filename);
            XmlSerializer xs = new XmlSerializer(typeof(Generation[]));


            Generation[] lol  = ((Generation[])xs.Deserialize(xr));
            int          test = lol.First().NumGeneration + 1;

            Generation.GenerationCpt = test;
            Individu.NbIndividus     = test * 10;


            Gens.Clear();
            foreach (Generation gen in lol)
            {
                Gens.Add(gen);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Compare le fitness de 2 individus aleatoires.
        /// </summary>
        /// <returns>L'individu ayant le fitness le plus élevé</returns>
        private Individu SelectParent()
        {
            int rnd1 = MidiComposer.GetRandom(0, Population.MAXINDIVIDUS);
            int rnd2 = MidiComposer.GetRandom(0, Population.MAXINDIVIDUS);


            Generation g  = Gens.Last();
            Individu   i1 = g.Individus[rnd1];
            Individu   i2 = g.Individus[rnd2];

            if (i1.Fitness > i2.Fitness)
            {
                return(i1);
            }
            else
            {
                return(i2);
            }
        }
Ejemplo n.º 8
0
        private void getprice(object sender, EventArgs e)
        {
            Gens gen = ((Gens)(Picker2.SelectedItem));

            if (gen != null)
            {
                var price = page2.GenList.Where(x => x.genname == gen.genname).FirstOrDefault().gencost;
                Label.Text     = String.Format("ราคา : {0:0.##}", price);
                Slider.Maximum = Convert.ToDouble(price);
                Slider.Minimum = 0;
                Slider.Value   = Convert.ToDouble(price);
                //setChart(price);
                setmicroChart(Convert.ToSingle(Slider.Value));
            }
            else
            {
                Label.Text = "ราคา :";
            }
        }
 public unsafe void Parse(EtwTraceNativeComponents.EVENT_RECORD *rawData)
 {
     if (rawData->EventHeader.Opcode == 17)
     {
         GCPerHeapHistoryTraceEvent gcperHeapHistoryTraceEvent = new GCPerHeapHistoryTraceEvent(GCPrivateEventsParser.providerGuid, "Microsoft-Windows-DotNETRuntimePrivate", rawData);
         List <long[]> list;
         if (!this.processData.TryGetValue(rawData->EventHeader.ProcessId, out list))
         {
             list = new List <long[]>();
             this.processData.Add(rawData->EventHeader.ProcessId, list);
         }
         long[] array = new long[4];
         for (Gens gens = Gens.Gen0; gens <= Gens.GenLargeObj; gens++)
         {
             long fragmentation = gcperHeapHistoryTraceEvent.GenData(gens).Fragmentation;
             array[(int)gens] = fragmentation;
         }
         list.Add(array);
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Populate a Gens movie file's header information
        /// </summary>
        public static void GMV(ref TreeView tv, ref TASMovie gmv)
        {
            Gens movie = (Gens)gmv;

            tv.Nodes.Clear();

            tv.Nodes.Add("Header");
            tv.Nodes[0].Nodes.Add("Signature:      " + movie.Header.Signature);
            tv.Nodes[0].Nodes.Add("Version:        " + movie.Header.Version.ToString());
            tv.Nodes[0].Nodes.Add("Movie Name:     " + movie.Extra.Description);
            tv.Nodes[0].Nodes.Add("Frame Count:    " + String.Format("{0:0,0}", movie.Header.FrameCount));
            tv.Nodes[0].Nodes.Add("Rerecord Count: " + String.Format("{0:0,0}", movie.Header.RerecordCount));

            if (movie.Header.Version > 0x09)
            {
                tv.Nodes[0].Nodes.Add("FPS:            " + movie.Options.FPS);
                tv.Nodes[0].Nodes.Add("Movie Start:    " + movie.Options.MovieStart);
            }

            tv.Nodes.Add("Controllers");
            tv.Nodes[1].Nodes.Add("Controller 1: true");
            tv.Nodes[1].Nodes[0].Nodes.Add("Config: " + movie.GMVSpecific.Player1Config + " button");
            tv.Nodes[1].Nodes.Add("Controller 2: true");
            tv.Nodes[1].Nodes[1].Nodes.Add("Config: " + movie.GMVSpecific.Player2Config + " button");
            tv.Nodes[1].Nodes.Add("Controller 3: false");

            if (movie.Header.Version > 0x09)
            {
                if (movie.Input.ControllerCount == 3)
                {
                    tv.Nodes[1].Nodes[2].Text = "Controller 3: true";
                }
            }

            movie = null; tv.ExpandAll(); tv.Nodes[0].EnsureVisible();
        }
Ejemplo n.º 11
0
        // Per generation stats.  
        public double GenSizeBeforeMB(Gens gen)
        {
            if (PerHeapHistories != null)
            {
                double ret = 0.0;
                for (int HeapIndex = 0; HeapIndex < PerHeapHistories.Count; HeapIndex++)
                    ret += PerHeapGenData[HeapIndex][(int)gen].SizeBefore / 1000000.0;
                return ret;
            }

            // When we don't have perheap history we can only estimate for gen0 and gen3.
            double Gen0SizeBeforeMB = 0;
            if (gen == Gens.Gen0)
                Gen0SizeBeforeMB = AllocedSinceLastGCBasedOnAllocTickMB[0];
            if (Index == 0)
            {
                return ((gen == Gens.Gen0) ? Gen0SizeBeforeMB : 0);
            }

            // Find a previous HeapStats.  
            GCHeapStatsTraceData heapStats = null;
            for (int j = Index - 1; ; --j)
            {
                if (j == 0)
                    return 0;
                heapStats = Events[j].HeapStats;
                if (heapStats != null)
                    break;
            }
            if (gen == Gens.Gen0)
                return Math.Max((heapStats.GenerationSize0 / 1000000.0), Gen0SizeBeforeMB);
            if (gen == Gens.Gen1)
                return heapStats.GenerationSize1 / 1000000.0;
            if (gen == Gens.Gen2)
                return heapStats.GenerationSize2 / 1000000.0;

            Debug.Assert(gen == Gens.GenLargeObj);

            if (HeapStats != null)
                return Math.Max(heapStats.GenerationSize3, HeapStats.GenerationSize3) / 1000000.0;
            else
                return heapStats.GenerationSize3 / 1000000.0;
        }
Ejemplo n.º 12
0
 public double GenSizeAfterMB(Gens gen)
 {
     if (gen == Gens.GenLargeObj)
         return HeapStats.GenerationSize3 / 1000000.0;
     if (gen == Gens.Gen2)
         return HeapStats.GenerationSize2 / 1000000.0;
     if (gen == Gens.Gen1)
         return HeapStats.GenerationSize1 / 1000000.0;
     if (gen == Gens.Gen0)
         return HeapStats.GenerationSize0 / 1000000.0;
     Debug.Assert(false);
     return double.NaN;
 }
Ejemplo n.º 13
0
 // Note that in 4.0 TotalPromotedSize is not entirely accurate (since it doesn't
 // count the pins that got demoted. We could consider using the PerHeap event data
 // to compute the accurate promoted size. 
 // In 4.5 this is accurate.
 public double GenPromotedMB(Gens gen)
 {
     if (gen == Gens.GenLargeObj)
         return HeapStats.TotalPromotedSize3 / 1000000.0;
     if (gen == Gens.Gen2)
         return HeapStats.TotalPromotedSize2 / 1000000.0;
     if (gen == Gens.Gen1)
         return HeapStats.TotalPromotedSize1 / 1000000.0;
     if (gen == Gens.Gen0)
         return HeapStats.TotalPromotedSize0 / 1000000.0;
     Debug.Assert(false);
     return double.NaN;
 }
Ejemplo n.º 14
0
 public double GenPinnedSurv(Gens gen)
 {
     if ((PerHeapHistories == null) || !(PerHeapGenData[0][0].HasPinnedSurv()))
         return double.NaN;
     double ret = 0.0;
     for (int HeapIndex = 0; HeapIndex < PerHeapHistories.Count; HeapIndex++)
         ret += PerHeapGenData[HeapIndex][(int)gen].PinnedSurv;
     return ret;
 }
Ejemplo n.º 15
0
 public double GenOutMB(Gens gen)
 {
     if (PerHeapHistories == null)
         return double.NaN;
     double ret = 0.0;
     for (int HeapIndex = 0; HeapIndex < PerHeapHistories.Count; HeapIndex++)
         ret += PerHeapGenData[HeapIndex][(int)gen].Out / 1000000.0;
     return ret;
 }
Ejemplo n.º 16
0
 public double GenFreeListBefore(Gens gen)
 {
     if (PerHeapHistories == null)
         return double.NaN;
     double ret = 0.0;
     for (int HeapIndex = 0; HeapIndex < PerHeapHistories.Count; HeapIndex++)
         ret += PerHeapGenData[HeapIndex][(int)gen].FreeListSpaceBefore;
     return ret;
 }
Ejemplo n.º 17
0
 public double GenFragmentationPercent(Gens gen)
 {
     return (GenFragmentationMB(gen) * 100.0 / GenSizeAfterMB(gen));
 }
Ejemplo n.º 18
0
        /// <summary>
        /// For a given heap, get what's allocated into gen0 or gen3.
        /// We calculate this differently on 4.0, 4.5 Beta and 4.5 RC+.
        /// The caveat with 4.0 and 4.5 Beta is that when survival rate is 0,
        /// We don't know how to calculate the allocated - so we just use the
        /// last GC's budget (We should indicate this in the tool)
        /// </summary>
        private double GetUserAllocatedPerHeap(int HeapIndex, Gens gen)
        {
            long prevObjSize = 0;
            if (Index > 0)
            {
                // If the prevous GC has that heap get its size.  
                var perHeapGenData = Events[Index - 1].PerHeapGenData;
                if (HeapIndex < perHeapGenData.Length)
                    prevObjSize = perHeapGenData[HeapIndex][(int)gen].ObjSizeAfter;
            }
            GCPerHeapHistoryGenData currentGenData = PerHeapGenData[HeapIndex][(int)gen];
            long survRate = currentGenData.SurvRate;
            long currentObjSize = currentGenData.ObjSizeAfter;
            double Allocated;

            if (Version == PerHeapEventVersion.V4_0)
            {
                if (survRate == 0)
                    Allocated = EstimateAllocSurv0(HeapIndex, gen);
                else
                    Allocated = (currentGenData.Out + currentObjSize) * 100 / survRate - prevObjSize;
            }
            else
            {
                Allocated = currentGenData.ObjSpaceBefore - prevObjSize;
            }

            return Allocated;
        }
Ejemplo n.º 19
0
 // When survival rate is 0, for certain releases (see comments for GetUserAllocatedPerHeap)
 // we need to estimate.
 private double EstimateAllocSurv0(int HeapIndex, Gens gen)
 {
     if (HasAllocTickEvents)
     {
         return AllocedSinceLastGCBasedOnAllocTickMB[(gen == Gens.Gen0) ? 0 : 1];
     }
     else
     {
         if (Index > 0)
         {
             // If the prevous GC has that heap get its size.  
             var perHeapGenData = Events[Index - 1].PerHeapGenData;
             if (HeapIndex < perHeapGenData.Length)
                 return perHeapGenData[HeapIndex][(int)gen].Budget;
         }
         return 0;
     }
 }
Ejemplo n.º 20
0
 public override string ToString()
 {
     return($"Weight: {Weight}, Fitness: {Fitness}, Gens: {string.Join(" ", Gens.Cast<bool>().Select(b => b ? "1" : "0"))}");
 }
Ejemplo n.º 21
0
        public double ObjSizeAfter(Gens gen)
        {
            double TotalObjSizeAfter = 0;

            if (PerHeapHistories != null)
            {
                for (int i = 0; i < PerHeapHistories.Count; i++)
                {
                    TotalObjSizeAfter += PerHeapGenData[i][(int)gen].ObjSizeAfter;
                }
            }

            return TotalObjSizeAfter;
        }
Ejemplo n.º 22
0
        //
        // Approximations we do in this function for V4_5 and prior:
        // On 4.0 we didn't seperate free list from free obj, so we just use fragmentation (which is the sum)
        // as an approximation. This makes the efficiency value a bit larger than it actually is.
        // We don't actually update in for the older gen - this means we only know the out for the younger 
        // gen which isn't necessarily all allocated into the older gen. So we could see cases where the 
        // out is > 0, yet the older gen's free list doesn't change. Using the younger gen's out as an 
        // approximation makes the efficiency value larger than it actually is.
        //
        // For V4_6 this requires no approximation.
        //
        public bool GetFreeListEfficiency(Gens gen, ref double Allocated, ref double FreeListConsumed)
        {
            // I am not worried about gen0 or LOH's free list efficiency right now - it's 
            // calculated differently.
            if ((PerHeapHistories == null) ||
                (gen == Gens.Gen0) ||
                (gen == Gens.GenLargeObj) ||
                (Index <= 0) ||
                !(PerHeapHistories[0].VersionRecognized))
            {
                return false;
            }

            int YoungerGen = (int)gen - 1;

            if (GCGeneration != YoungerGen)
                return false;

            if (PerHeapHistories[0].V4_6)
            {
                Allocated = 0;
                FreeListConsumed = 0;
                for (int HeapIndex = 0; HeapIndex < PerHeapHistories.Count; HeapIndex++)
                {
                    GCPerHeapHistoryTraceData3 hist = (GCPerHeapHistoryTraceData3)PerHeapHistories[HeapIndex];
                    Allocated += hist.FreeListAllocated;
                    FreeListConsumed += hist.FreeListAllocated + hist.FreeListRejected;
                }
                return true;
            }

            // I am not using MB here because what's promoted from gen1 can easily be less than a MB.
            double YoungerGenOut = 0;
            double FreeListBefore = 0;
            double FreeListAfter = 0;
            // Includes fragmentation. This lets us know if we had to expand the size.
            double GenSizeBefore = 0;
            double GenSizeAfter = 0;
            for (int HeapIndex = 0; HeapIndex < PerHeapHistories.Count; HeapIndex++)
            {
                YoungerGenOut += PerHeapGenData[HeapIndex][YoungerGen].Out;
                GenSizeBefore += PerHeapGenData[HeapIndex][(int)gen].SizeBefore;
                GenSizeAfter += PerHeapGenData[HeapIndex][(int)gen].SizeAfter;
                if (Version == PerHeapEventVersion.V4_0)
                {
                    // Occasionally I've seen a GC in the middle that simply missed some events,
                    // some of which are PerHeap hist events so we don't have data.
                    if (Events[Index - 1].PerHeapGenData == null)
                        return false;
                    FreeListBefore += Events[Index - 1].PerHeapGenData[HeapIndex][(int)gen].Fragmentation;
                    FreeListAfter += PerHeapGenData[HeapIndex][(int)gen].Fragmentation;
                }
                else
                {
                    FreeListBefore += PerHeapGenData[HeapIndex][(int)gen].FreeListSpaceBefore;
                    FreeListAfter += PerHeapGenData[HeapIndex][(int)gen].FreeListSpaceAfter;
                }
            }

            double GenSizeGrown = GenSizeAfter - GenSizeBefore;

            // This is the most accurate situation we can calculuate (if it's not accurate it means
            // we are over estimating which is ok.
            if ((GenSizeGrown == 0) && ((FreeListBefore > 0) && (FreeListAfter >= 0)))
            {
                Allocated = YoungerGenOut;
                FreeListConsumed = FreeListBefore - FreeListAfter;
                // We don't know how much of the survived is pinned so we are overestimating here.
                if (Allocated < FreeListConsumed)
                    return true;
            }

            return false;
        }
Ejemplo n.º 23
0
 private void Survival()
 {
     Gens.RemoveAt(0);
 }
Ejemplo n.º 24
0
 public GCPerHeapHistoryTraceEvent.GCPerHeapHistoryGenData GenData(Gens genNumber)
 {
     return(new GCPerHeapHistoryTraceEvent.GCPerHeapHistoryGenData(this, this.SizeOfGenData * (int)genNumber));
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Get what's allocated into gen0 or gen3. For server GC this gets the total for 
        /// all heaps.
        /// </summary>
        public double GetUserAllocated(Gens gen)
        {
            Debug.Assert((gen == Gens.Gen0) || (gen == Gens.GenLargeObj));

            if ((Type == GCType.BackgroundGC) && (gen == Gens.Gen0))
            {
                return AllocedSinceLastGCBasedOnAllocTickMB[(int)gen];
            }

            if (PerHeapHistories != null && Index > 0 && Events[Index - 1].PerHeapHistories != null)
            {
                double TotalAllocated = 0;
                if (Index > 0)
                {
                    for (int i = 0; i < PerHeapHistories.Count; i++)
                    {
                        double Allocated = GetUserAllocatedPerHeap(i, gen);

                        TotalAllocated += Allocated / 1000000.0;
                    }

                    return TotalAllocated;
                }
                else
                {
                    return GenSizeBeforeMB(gen);
                }
            }

            return AllocedSinceLastGCBasedOnAllocTickMB[(gen == Gens.Gen0) ? 0 : 1];
        }
Ejemplo n.º 26
0
        public void CommandExecuted(ICommand command)
        {
            if (command is ApplyRenameCommand)
            {
                RenameApplied(command as ApplyRenameCommand);
            }
            if (!(command is IFileSyncCommand))
            {
                return;
            }
            var items   = Container.Resolve <IRepository>().AllOf <IDataRecord>().ToArray();
            var gensNow = new Dictionary <string, GenFileInfo>();

            foreach (var p in InvertGraphEditor.GetAllCodeGenerators(
                         Container.Resolve <DatabaseService>().CurrentConfiguration, items))
            {
                var key = Path.GetFileName(p.Filename);
                if (!gensNow.ContainsKey(key))
                {
                    gensNow.Add(key, new GenFileInfo(Path.Combine(Application.dataPath, p.RelativeFullPathName), p));
                }
            }

            var deleteList = new List <string>();

            foreach (var item in Gens)
            {
                if (!gensNow.ContainsKey(item.Key))
                {
                    // Its been removed or renamed

                    if (File.Exists(item.Value.FullPath))
                    {
                        deleteList.Add(item.Value.FullPath);
                    }
                }
                else
                {
                    var nowItem = gensNow[item.Key];
                    if (nowItem.Generator.ObjectData == item.Value.Generator.ObjectData)
                    {
                        // It has been moved
                        if (File.Exists(item.Value.FullPath))
                        {
                            File.Move(item.Value.FullPath, nowItem.FullPath);
                        }
                    }
                }
            }

            Gens.Clear();
            GC.Collect();
            IsRename = false;
            if (deleteList.Count > 0)
            {
                if (InvertGraphEditor.Platform.MessageBox("Warning",
                                                          string.Format("You've deleted a record that has {0} file(s) associated with it.  Would you like to remove them?", deleteList.Count),
                                                          "YES (Recommended)", "NO they are special!"))
                {
                    foreach (var item in deleteList)
                    {
                        File.Delete(item);
                    }
                }
                this.Execute(new SaveAndCompileCommand()
                {
                    ForceCompileAll = true
                });
            }
        }
Ejemplo n.º 27
0
        public double SurvivalPercent(Gens gen)
        {
            double retSurvRate = double.NaN;

            long SurvRate = 0;

            if (gen == Gens.GenLargeObj)
            {
                if (GCGeneration < 2)
                {
                    return retSurvRate;
                }
            }
            else if ((int)gen > GCGeneration)
            {
                return retSurvRate;
            }

            if (PerHeapHistories != null)
            {
                for (int i = 0; i < PerHeapHistories.Count; i++)
                {
                    SurvRate += PerHeapGenData[i][(int)gen].SurvRate;
                }

                SurvRate /= PerHeapHistories.Count;
            }

            retSurvRate = SurvRate;

            return retSurvRate;
        }
Ejemplo n.º 28
0
 public override string ToString()
 {
     return('{' + string.Join(";", Gens.Select(g => string.Format("{0,0:N1}", g))) + '}');
 }