public OptimizationCase(OptimizationRules boundaries) { foreach (string parameter in Enum.GetNames(typeof(Symbols))) { Parameters.Add(0.0); } Boundaries = boundaries; }
public OptimizationCase(PhysicalBridge bridge) { foreach (string parameter in Enum.GetNames(typeof(Symbols))) { Parameters.Add(Converters.ToMeters(bridge.Superstructure.ParametersMap.get_Item(parameter).AsDouble())); } Boundaries = new OptimizationRules(); foreach (int i in Enum.GetValues(typeof(Symbols))) { Boundaries.Min[i] = Parameters[i]; Boundaries.Max[i] = Parameters[i]; } }
public OptimizationCase(string encoded) { foreach (Symbols i in Enum.GetValues(typeof(Symbols))) { Parameters.Add(0.0); } Boundaries = new OptimizationRules(); encoded = encoded.Remove(0, encoded.IndexOf("\t") + 1); while (encoded.Length > 0) { string trimmed; if (encoded.Contains("\t")) { trimmed = encoded.Substring(0, encoded.IndexOf("\t")); encoded = encoded.Substring(encoded.IndexOf("\t") + 1); } else { trimmed = encoded; encoded = ""; } string paramName = trimmed.Substring(0, trimmed.IndexOf(":")); string paramValue = trimmed.Substring(trimmed.IndexOf(":") + 2); paramValue = paramValue.Substring(0, paramValue.IndexOf(" ")); if (Enum.GetNames(typeof(Symbols)).ToList().Contains(paramName) && double.TryParse(paramValue, out double val)) { int index = Enum.GetNames(typeof(Symbols)).ToList().IndexOf(paramName); Parameters[index] = val; string minBound, maxBound; minBound = trimmed.Substring(trimmed.IndexOf("(") + 1).TrimEnd(')'); maxBound = minBound; minBound = minBound.Substring(0, minBound.IndexOf(" ")); maxBound = maxBound.Substring(maxBound.LastIndexOf(" ") + 1); if (double.TryParse(minBound, out double minVal) && double.TryParse(maxBound, out double maxVal)) { Boundaries.Min[index] = minVal; Boundaries.Max[index] = maxVal; } } } }
public OptimizationCase(PhysicalBridge seed, OptimizationRules boundaries = null, Random rnd = null) { double minEdge = Converters.ToMeters(seed.Superstructure.ParametersMap.get_Item("O1").AsDouble()); double maxEdge = Converters.ToMeters(seed.Superstructure.ParametersMap.get_Item("O5").AsDouble()); foreach (Symbols i in Enum.GetValues(typeof(Symbols))) { Parameters.Add(0.0); } if (boundaries == null) { boundaries = new OptimizationRules(minEdge, maxEdge); } Boundaries = boundaries; //Case generation: if (rnd == null) { rnd = new Random(); } Parameters[(int)Symbols.BL] = Boundaries.Min[(int)Symbols.BL] + rnd.NextDouble() * (Boundaries.Max[(int)Symbols.BL] - Boundaries.Min[(int)Symbols.BL]); Parameters[(int)Symbols.BP] = Parameters[(int)Symbols.BL]; Parameters[(int)Symbols.HL] = Boundaries.Min[(int)Symbols.HL] + rnd.NextDouble() * (Boundaries.Max[(int)Symbols.HL] - Boundaries.Min[(int)Symbols.HL]); Parameters[(int)Symbols.HP] = Parameters[(int)Symbols.HL]; Parameters[(int)Symbols.BL1] = Boundaries.Min[(int)Symbols.BL1] + rnd.NextDouble() * (Boundaries.Max[(int)Symbols.BL1] - Boundaries.Min[(int)Symbols.BL1]); Parameters[(int)Symbols.BL2] = Parameters[(int)Symbols.BL1]; Parameters[(int)Symbols.BP1] = Parameters[(int)Symbols.BL1]; Parameters[(int)Symbols.BP2] = Parameters[(int)Symbols.BL1]; double totalGirderWidth = Parameters[(int)Symbols.BL] + Parameters[(int)Symbols.BL1] + Parameters[(int)Symbols.BL2]; double minOffset, maxOffset; if (rnd.NextDouble() < 0.5) { minOffset = Boundaries.Min[(int)Symbols.OL] + Boundaries.MinCantileverOverhang + 0.5 * totalGirderWidth; maxOffset = Boundaries.Max[(int)Symbols.OL] - Boundaries.MinCantileverOverhang - totalGirderWidth - Boundaries.MinSpanLength - 0.5 * totalGirderWidth; Parameters[(int)Symbols.OL] = minOffset + rnd.NextDouble() * (maxOffset - minOffset); minOffset = Parameters[(int)Symbols.OL] + Boundaries.MinSpanLength + totalGirderWidth; maxOffset = Boundaries.Max[(int)Symbols.OP] - Boundaries.MinCantileverOverhang - 0.5 * totalGirderWidth; Parameters[(int)Symbols.OP] = minOffset + rnd.NextDouble() * (maxOffset - minOffset); } else { minOffset = Boundaries.Min[(int)Symbols.OP] + Boundaries.MinCantileverOverhang + totalGirderWidth + Boundaries.MinSpanLength + 0.5 * totalGirderWidth; maxOffset = Boundaries.Max[(int)Symbols.OP] - Boundaries.MinCantileverOverhang - 0.5 * totalGirderWidth; Parameters[(int)Symbols.OP] = minOffset + rnd.NextDouble() * (maxOffset - minOffset); minOffset = Boundaries.Min[(int)Symbols.OL] + Boundaries.MinCantileverOverhang + totalGirderWidth + 0.5 * totalGirderWidth; maxOffset = Parameters[(int)Symbols.OP] - Boundaries.MinSpanLength - totalGirderWidth; Parameters[(int)Symbols.OL] = minOffset + rnd.NextDouble() * (maxOffset - minOffset); } if (rnd.NextDouble() < 0.5) { Parameters[(int)Symbols.WL] = 0.000; Parameters[(int)Symbols.WP] = 0.000; } else { double cantileverOverhang = Math.Min(Parameters[(int)Symbols.OL] - minEdge, maxEdge - Parameters[(int)Symbols.OP]) - 0.5 * totalGirderWidth; if (cantileverOverhang > Boundaries.Max[(int)Symbols.WL]) { cantileverOverhang = Boundaries.Max[(int)Symbols.WL]; } Parameters[(int)Symbols.WL] = Boundaries.Min[(int)Symbols.WL] + rnd.NextDouble() * (cantileverOverhang - Boundaries.Min[(int)Symbols.WL]); Parameters[(int)Symbols.WP] = Parameters[(int)Symbols.WL]; } double spanLength = Parameters[(int)Symbols.OP] - Parameters[(int)Symbols.OL] - totalGirderWidth; Parameters[(int)Symbols.PL] = Boundaries.Min[(int)Symbols.PL] + rnd.NextDouble() * (Math.Min(0.5 * spanLength, Boundaries.Max[(int)Symbols.PL]) - Boundaries.Min[(int)Symbols.PL]); Parameters[(int)Symbols.PP] = Parameters[(int)Symbols.PL]; Parameters[(int)Symbols.G1] = Boundaries.Min[(int)Symbols.G1] + rnd.NextDouble() * (Boundaries.Max[(int)Symbols.G1] - Boundaries.Min[(int)Symbols.G1]); Parameters[(int)Symbols.G11] = Parameters[(int)Symbols.G1]; Parameters[(int)Symbols.G3] = Boundaries.Min[(int)Symbols.G3] + rnd.NextDouble() * (Boundaries.Max[(int)Symbols.G3] - Boundaries.Min[(int)Symbols.G3]); Parameters[(int)Symbols.G9] = Parameters[(int)Symbols.G3]; if (Parameters[(int)Symbols.G3] < Parameters[(int)Symbols.G1]) { Parameters[(int)Symbols.G3] = Parameters[(int)Symbols.G1]; } if (Parameters[(int)Symbols.WL] == 0.000) { Parameters[(int)Symbols.G2] = Parameters[(int)Symbols.G3]; } else { Parameters[(int)Symbols.G2] = Boundaries.Min[(int)Symbols.G2] + rnd.NextDouble() * (Boundaries.Max[(int)Symbols.G2] - Boundaries.Min[(int)Symbols.G2]); if (Parameters[(int)Symbols.G2] < Parameters[(int)Symbols.G1]) { Parameters[(int)Symbols.G2] = Parameters[(int)Symbols.G1]; } if (Parameters[(int)Symbols.G2] > Parameters[(int)Symbols.G3]) { Parameters[(int)Symbols.G2] = Parameters[(int)Symbols.G3]; } } Parameters[(int)Symbols.G10] = Parameters[(int)Symbols.G2]; Parameters[(int)Symbols.G5] = Boundaries.Min[(int)Symbols.G5] + rnd.NextDouble() * (Boundaries.Max[(int)Symbols.G5] - Boundaries.Min[(int)Symbols.G5]); Parameters[(int)Symbols.G7] = Parameters[(int)Symbols.G5]; if (Parameters[(int)Symbols.PL] == 0.000) { Parameters[(int)Symbols.G4] = Parameters[(int)Symbols.G5]; } else { Parameters[(int)Symbols.G4] = Boundaries.Min[(int)Symbols.G4] + rnd.NextDouble() * (Boundaries.Max[(int)Symbols.G4] - Boundaries.Min[(int)Symbols.G4]); if (Parameters[(int)Symbols.G4] < Parameters[(int)Symbols.G5]) { Parameters[(int)Symbols.G4] = Parameters[(int)Symbols.G5]; } } Parameters[(int)Symbols.G8] = Parameters[(int)Symbols.G4]; for (int p = 0; p < Parameters.Count(); p++) { Parameters[p] = Math.Round(Math.Round(Parameters[p] / 0.0005) * 0.0005, 4); } }