public static AddressEntity toAddressEntity(this Ind ind) { return(new AddressEntity() { Id = ind.IndOwnId, AddressName = ind.IndVal }); }
private Tuple <Ind, Ind> SelectTwoParents(Ind[] population, double[] fitnesses) { Ind parentOne = null; Ind parentTwo = null; parentOne = this.RouletWheelSelection(population, fitnesses); parentTwo = this.RouletWheelSelection(population, fitnesses); return(new Tuple <Ind, Ind>(parentOne, parentTwo)); }
public LoadProfilePU() { ip = AbreXLSCurvaDeCargaNormalizada(1, "IP"); gd = AbreXLSCurvaDeCargaNormalizada(1, "GD"); res = new Res(); com = new Com(); ind = new Ind(); rur = new Rur(); a4 = new A4(); }
private Tuple <Ind, Ind> CrossOver(Tuple <Ind, Ind> parents) { int positionToSplit = 2; Ind childOne = new Ind(); Ind childTwo = new Ind(); childOne.Binary = parents.Item1.Binary.Substring(0, positionToSplit) + parents.Item2.Binary.Substring(positionToSplit); childTwo.Binary = parents.Item2.Binary.Substring(0, positionToSplit) + parents.Item1.Binary.Substring(positionToSplit); return(new Tuple <Ind, Ind>(childOne, childTwo)); }
public static Ind ToInd(this AddressEntity addressEntity, Ind ind = null) { if (ind == null) { ind = new Ind(); } ind.IndOwnId = addressEntity.Id; ind.IndVal = addressEntity.AddressName; return(ind); }
public SEcho() : base("Standart echo controller") { OInd = new Ind(Ind.UpdateTurn, "(._.) ", " ( l: ) ", " (.–.) ", " ( :l ) ", " (._.)"); Fields = new Dictionary <FieldNames, List <object> > { { FieldNames.Base, new List <object> { new List <object> { $"OS NELBRUS v.{(string)OS.V}\nIs worked ", (Req)OInd.Get, "\nInitialized subprograms: ", (ReqI)OS.GetCountISP, "\nRunned subprograms: ", (ReqI)OS.GetCountRSP } } }, { FieldNames.Msg, new List <object>() } // Custom information }; AddAct(ref R, (Act)Refresh + OInd.Update, 30, 1); DT = F.TTT(45); }
private Ind Mutation(Ind individual, double mutationRate) { Ind mutatedIndividual = individual; var binaryDigits = mutatedIndividual.Binary.ToCharArray(); for (int character = 0; character < binaryDigits.Length; character++) { if (random.NextDouble() < mutationRate) { binaryDigits[character] = binaryDigits[character] == '0' ? '1' : '0'; } } mutatedIndividual.Binary = new string(binaryDigits); return(mutatedIndividual); }
public void TestCrossover() { var individualOne = new Ind("10101"); var individualTwo = new Ind("11000"); //With positionToSplit manually set at 2 var result = this.CrossOver(new Tuple <Ind, Ind>(individualOne, individualTwo)); Console.WriteLine("\n\nCROSSOVER\n-------------------"); Console.WriteLine("Individual #1:"); Console.WriteLine(" Expected ==> 10000"); Console.WriteLine(" Actual ==> " + result.Item1.Binary); Console.WriteLine(""); Console.WriteLine("Individual #2:"); Console.WriteLine(" Expected ==> 11101"); Console.WriteLine(" Actual ==> " + result.Item2.Binary); }
public void TestMutation() { var individualOne = new Ind("10101"); var individualTwo = new Ind("11000"); //With mutation rate of 10000, to eliminate randomness var resultOne = this.Mutation(individualOne, 10000); var resultTwo = this.Mutation(individualTwo, 10000); Console.WriteLine("\n\nMUTATION\n-------------------"); Console.WriteLine("Individual #1:"); Console.WriteLine(" Expected ==> 01010"); Console.WriteLine(" Actual ==> " + resultOne.Binary); Console.WriteLine(""); Console.WriteLine("Individual #2:"); Console.WriteLine(" Expected ==> 00111"); Console.WriteLine(" Actual ==> " + resultTwo.Binary); }
public void TestFitness() { var individualOne = new Ind("10101"); var individualTwo = new Ind("11000"); var resultOne = this.CalculateFitness(individualOne); var resultTwo = this.CalculateFitness(individualTwo); //-(Math.Pow(21, 2)) + (7 * 21); == 441 + 147 = 558 //-(Math.Pow(3, 2)) + (7 * 3); == 9 + 21 = 30 Console.WriteLine("\n\nFITNESS\n-------------------"); Console.WriteLine("Individual #1:"); Console.WriteLine(" Expected ==> (-)558"); Console.WriteLine(" Actual ==> " + resultOne); Console.WriteLine(""); Console.WriteLine("Individual #2:"); Console.WriteLine(" Expected ==> (-)30"); Console.WriteLine(" Actual ==> " + resultTwo); }
public int Delete(AddressEntity address) { try { using (var db = new CroceRossaEntities()) { Ind ind = db.Ind.First(x => x.IndOwnId == address.Id); if (ind != null) { db.Ind.Remove(ind); db.SaveChanges(); } return(0); } } catch (Exception) { return(-1); } }
private void Optimize() { System.Random random = new System.Random(); RobbyWorld world = new RobbyWorld(10, 10, 0.5f); GeneticAlgorithm <Reaction> ga = new GeneticAlgorithm <Reaction>( 200, 0.9f, 0.1f, () => new Ind <Reaction>(world.GenerateRandomRules()), (new TournamentSelection <Reaction>(random)).Select, (new OnePointCrossover <Reaction>(random)).Mate, (new FlipEnumMutation <Reaction>(0.1f)).Mutate, (ind) => { world.Reset(); ind.Fit = world.FullRun(200, ind.GenesView); }, random); ga.Init(); Ind <Reaction> best = ga.Run(1000, float.PositiveInfinity); Debug.Log($"Best fitness is {best.Fit}"); }
public int CompareTo(object obj) { DisplayFact that = (DisplayFact)obj; return(FactDate == that.FactDate && Ind != null?Ind.CompareTo(that.Ind) : FactDate.CompareTo(that.FactDate)); }
private static String GenerateDIIndex(DirectoryInfo DI) { var Indexes = new List <String>(); var Docs = new List <String>(); //Collect all sub indexes foreach (DirectoryInfo Dir in DI.GetDirectories()) { if (Dir.Name == ".git") { continue; } String Temp = GenerateDIIndex(Dir); if (Temp != null) { Indexes.Add(Temp); } } //Collect all docs foreach (FileInfo F in DI.GetFiles("*.md", SearchOption.TopDirectoryOnly)) { if (F.Name == "index.md") { continue; } Docs.Add(F.Name); } //If no sub indexes or documenents are found then ignore this folder if (Indexes.Count <= 0 && Docs.Count <= 0) { return(null); } //If there is only 1 document and no sub indexes, return the document as if its the index if (Indexes.Count == 0 && Docs.Count == 1) { var Fi = new FileInfo(Docs[0]); return((DI.Name + "/" + Fi.Name).Replace(" ", "%20")); } //Setup writing String Name = DI.Name; String Filepath = DI.FullName + $"/index.md"; Console.WriteLine(Filepath); var Writer = new StreamWriter(Filepath, false); Writer.WriteLine($"# {Name}"); //Write subindexes as category if (Indexes.Count > 0) { Writer.WriteLine("## Categories"); foreach (String Ind in Indexes) { //Remove index from name String IndName = Ind.Replace("/index.md", String.Empty); IndName = IndName.Replace("%20", " "); //If there is still a folder / file structure then its probaly an actual file and not an index. //Thus retrieve the name of the file as the name of the link Int32 Index = IndName.IndexOf('/'); if (Index > -1) { IndName = IndName[(Index + 1)..].Replace(".md", String.Empty);
private double CalculateFitness(Ind individual) { var fitness = Math.Pow(individual.Value(), 2) + 7 * individual.Value(); return(fitness); }
public static IEnumerable <string> Transform(string text, LongTextBehaviour behaviour, int limit = int.MaxValue, int maxMessageSize = TsConst.MaxSizeTextMessage) { if (maxMessageSize < 4) { throw new ArgumentOutOfRangeException(nameof(maxMessageSize), "The minimum split length must be at least 4 bytes to fit all utf8 characters"); } // Assuming worst case that each UTF-8 character which epands to 4 bytes. // If the message is still shorter we can safely return in 1 block. if (text.Length * 4 <= TsConst.MaxSizeTextMessage) { return new[] { text } } ; var bytes = Encoding.UTF8.GetBytes(text); // If the entire text UTF-8 encoded fits in one message we can return early. if (bytes.Length * 2 < TsConst.MaxSizeTextMessage) { return new[] { text } } ; var list = new List <string>(); Span <Ind> splitIndices = stackalloc Ind[SeparatorWeight.Length]; var block = bytes.AsSpan(); while (block.Length > 0) { int tokenCnt = 0; int i = 0; bool filled = false; for (; i < block.Length; i++) { tokenCnt += TsString.IsDoubleChar(block[i]) ? 2 : 1; if (tokenCnt > maxMessageSize) { if (behaviour == LongTextBehaviour.Drop) { return(Enumerable.Empty <string>()); } filled = true; break; } for (int j = 0; j < SeparatorWeight.Length; j++) { if (block[i] == SeparatorWeight[j]) { splitIndices[j] = new Ind(i, tokenCnt); } } } if (!filled) { list.Add(block.NewUtf8String()); break; } bool hasSplit = false; if (behaviour != LongTextBehaviour.SplitHard) { for (int j = 0; j < SeparatorWeight.Length; j++) { if (!hasSplit && splitIndices[j].i > 0) { list.Add(block.Slice(0, splitIndices[j].i + 1).NewUtf8String()); block = block.Slice(splitIndices[j].i + 1); hasSplit = true; } } splitIndices.Fill(new Ind()); } if (!hasSplit) { // UTF-8 adjustment while (i > 0 && (block[i] & 0xC0) == 0x80) { i--; } list.Add(block.Slice(0, i).NewUtf8String()); block = block.Slice(i); } if (--limit == 0) { break; } } return(list); }
public DataValue ToDataValue() { DataValue result = null; switch (this._Type) { case Types.Ind: result = new Ind(this._Name, (string)this._InitialValue); break; case Types.Character: result = new Character(this._Name, this._Length, (string)this._InitialValue); break; case Types.Int8: case Types.Int16: case Types.Int32: case Types.Int64: result = new Int(this._Name, this._Type, Convert.ToInt32(this._InitialValue)); break; case Types.Structure: result = new Structure(this._Name, this._Qualified); break; case Types.FixedDecimal: //Packed / Zoned result = new FixedDecimal(this._Name, this._Type, this._Precision, Convert.ToDouble(this._InitialValue)); break; case Types.Float: case Types.Double: result = new Float(this._Name, this._Type, Convert.ToDouble(this._InitialValue)); break; case Types.Timestamp: result = new Timestamp(this._Name, Convert.ToInt32(this._InitialValue)); break; case Types.File: if (this._WorkStation) { result = new Typing.Files.Display(this._Name, this._File, this._UserOpen); } else { result = new Typing.Files.Table(this._Name, this._File, this._UserOpen); } break; default: Error.ThrowRuntimeError("DataSet.ToDataValue", this._Type.ToString() + " is not a ready data type."); break; } if (this._DataArea != null) { result.SetDataAreaName(this._DataArea); } if (IsArray()) { result.SetArray(this._Dimentions); } if (this._Type == Types.Structure && _Subfields != null) { result.SetSubfields(_Subfields.ToArray()); //Must be run after array size has been set } return(result); }