public static SerializedModel CreateSerializedModel(string unitDefCSVPath, BuildingUnitMix desiredUnitMix, Seismicity seismicity, double buildingHeight, int numberOfStories, Line2D mainCorridor, Line2D leftLeg, Line2D middleLeg, Line2D rightLeg, double unitDepth, double hallWidth, RandomizedBuilding randomizedBuilding) { double randomizedPercent = 0.75; var importedUnitList = new List <BuildingUnit>(); var csv = File.ReadAllLines(unitDefCSVPath); for (int i = 1; i < csv.Length; i++) { var lineSplit = csv[i].Split(','); importedUnitList.Add(new BuildingUnit(lineSplit[0], lineSplit[1], Convert.ToDouble(lineSplit[2]), Convert.ToDouble(lineSplit[3]), Convert.ToDouble(lineSplit[4]), Convert.ToDouble(lineSplit[5]))); } List <Polygon2D> polyUnits = new List <Polygon2D>(); List <string> unitNames = new List <string>(); List <Line2D> shearWallLines = new List <Line2D>(); List <Line2D> lineList = new List <Line2D>(); MainCorridor mainCorridorObject = new MainCorridor(); FittingAlgorithm.GetBuildingLayout(importedUnitList, desiredUnitMix, mainCorridor, leftLeg, middleLeg, rightLeg, unitDepth, hallWidth, out polyUnits, out unitNames, out shearWallLines, out lineList, out mainCorridorObject); var outlinePoints = FittingAlgorithm.GetOutlinePoints(unitDepth, hallWidth, mainCorridorObject); var outlinePolygon = new Polygon2D(outlinePoints); return(new SerializedModel(buildingHeight, numberOfStories, seismicity, shearWallLines, lineList, outlinePolygon, polyUnits, randomizedBuilding, randomizedPercent)); }
public void UnitDistributorTest() { var unitList = new List <BuildingUnit>(); var path = System.Reflection.Assembly.GetExecutingAssembly().Location; var parent = Directory.GetParent(Directory.GetParent(Directory.GetParent(Directory.GetParent(Directory.GetParent(Directory.GetParent(path).FullName).FullName).FullName).FullName).FullName); var filePath = parent + @"\extern\units.csv"; var csv = File.ReadAllLines(filePath); for (int i = 1; i < csv.Length; i++) { var lineSplit = csv[i].Split(","); unitList.Add(new BuildingUnit(lineSplit[0], lineSplit[1], Convert.ToDouble(lineSplit[2]), Convert.ToDouble(lineSplit[3]), Convert.ToDouble(lineSplit[4]), Convert.ToDouble(lineSplit[5]))); } Assert.That(unitList.Count > 0); var desiredUnitMix = new BuildingUnitMix() { { "S", 0.15 }, { "A", 0.15 }, { "B", 0.40 }, { "C", 0.40 } }; double corridorLength = 300; double unitDepth = 27; double buildingAreaTotal = corridorLength * 2 * unitDepth; var currentPercentage = new BuildingUnitMix() { { "S", 0 }, { "A", 0 }, { "B", 0 }, { "C", 0 } }; var unitPriority = new List <string>() { "C", "B", "A", "S" }; var totalUnitList = new List <Tuple <string, double> >(); var usedLength = 0d; var unitLine = FittingAlgorithm.CreateUnitLine(unitList, desiredUnitMix, corridorLength, ref currentPercentage, unitPriority, ref totalUnitList, ref usedLength); Assert.That(unitLine.Count(), Is.GreaterThan(0)); }
private static void GetBuildingLayout(string defPath, string mixPath, Line mainCorridor, Line leftLeg, Line middleLeg, Line rightLeg, double unitDepth, double hallWidth, out List <PolylineCurve> polyUnits, out List <string> unitNames, out List <Line> shearWallLines, out List <Line> lineList, out PolylineCurve boundary, out List <double> percentMix) { var unitList = new List <BuildingUnit>(); var csv = File.ReadAllLines(defPath); for (int i = 1; i < csv.Length; i++) { var lineSplit = csv[i].Split(','); unitList.Add(new BuildingUnit(lineSplit[0], lineSplit[1], Convert.ToDouble(lineSplit[2]), Convert.ToDouble(lineSplit[3]), Convert.ToDouble(lineSplit[4]), Convert.ToDouble(lineSplit[5]))); } BuildingUnitMix desiredUnitMix = new BuildingUnitMix(); csv = File.ReadAllLines(mixPath); for (int i = 1; i < csv.Length; i++) { var lineSplit = csv[i].Split(','); desiredUnitMix.Add(lineSplit[0], Convert.ToDouble(lineSplit[2])); } var corridors = new List <Corridor>(); var mainCorridorObject = new MainCorridor(); var location = CorridorLocation.Main; var corridorLineList = new List <UnitsLine>(); var leftLegObject = new Corridor(); if (leftLeg.Length > unitDepth + hallWidth / 2) { var leftLine2D = CreateLine2D(leftLeg); location = CorridorLocation.LeftLeg; leftLegObject = new Corridor(leftLine2D, unitDepth, hallWidth, location); corridorLineList.AddRange(leftLegObject.GetLines()); } var midLegObject = new Corridor(); if (middleLeg.Length > unitDepth + hallWidth / 2) { var midLine2D = CreateLine2D(middleLeg); location = CorridorLocation.MiddleLeg; midLegObject = new Corridor(midLine2D, unitDepth, hallWidth, location); corridorLineList.AddRange(midLegObject.GetLines()); } var rightLegObject = new Corridor(); if (rightLeg.Length > unitDepth + hallWidth / 2) { var rightLine2D = CreateLine2D(rightLeg); location = CorridorLocation.RightLeg; rightLegObject = new Corridor(rightLine2D, unitDepth, hallWidth, location); corridorLineList.AddRange(rightLegObject.GetLines()); } var mainLine2D = CreateLine2D(mainCorridor); location = CorridorLocation.Main; mainCorridorObject.CenterLine = mainLine2D; mainCorridorObject.UnitDepth = unitDepth; mainCorridorObject.HallWidth = hallWidth; mainCorridorObject.CorridorLocation = location; mainCorridorObject.LeftLeg = leftLegObject; mainCorridorObject.MiddleLeg = midLegObject; mainCorridorObject.RightLeg = rightLegObject; mainCorridorObject.CalculateMainLines(); var currentPercentage = new BuildingUnitMix(); foreach (var kvp in desiredUnitMix) { currentPercentage.Add(kvp.Key, 0); } corridorLineList.AddRange(mainCorridorObject.GetLines()); corridorLineList.OrderBy(x => x.Line.Length); double usedLength = 0; var unitPriority = new List <string>() { "C", "B", "A", "S" }; var totalUnitList = new List <Tuple <string, double> >(); polyUnits = new List <PolylineCurve>(); unitNames = new List <string>(); shearWallLines = new List <Line>(); foreach (var corridorLine in corridorLineList) { var corridorLength = corridorLine.Line.Length; var units = FittingAlgorithm.CreateUnitLine(unitList, desiredUnitMix, corridorLength, ref currentPercentage, unitPriority, ref totalUnitList, ref usedLength); var buildingUnits = new List <BuildingUnit>(); double startLength = 0; var lineVector = corridorLine.Line.Direction; var angle = new Vector2D(1, 0).SignedAngleTo(lineVector); foreach (var unit in units) { var matchingUnit = unitList.Single(x => (x.Type == unit.Item1 && x.Width == unit.Item2)); matchingUnit.Rotation = angle; matchingUnit.Location = corridorLine.Line.StartPoint + startLength * lineVector; var unitPolygon = matchingUnit.GetPolygon(); var unitWallLines = matchingUnit.GetShearWallLines(); foreach (var unitLine in unitWallLines) { shearWallLines.Add(new Line(new Point3d(unitLine.StartPoint.X, unitLine.StartPoint.Y, 0), new Point3d(unitLine.EndPoint.X, unitLine.EndPoint.Y, 0))); } var unitPoints = unitPolygon.ToPolyLine2D().Vertices; var point3dList = new List <Point3d>(); foreach (var vertex in unitPoints) { point3dList.Add(new Point3d(vertex.X, vertex.Y, 0)); } var unitPolyline = new PolylineCurve(point3dList); polyUnits.Add(unitPolyline); unitNames.Add(matchingUnit.Type); buildingUnits.Add(matchingUnit); startLength += matchingUnit.Width; } corridorLine.BuildingUnits = buildingUnits; } lineList = new List <Line>(); foreach (var corridorLine in corridorLineList) { lineList.Add(new Line(new Point3d(corridorLine.Line.StartPoint.X, corridorLine.Line.StartPoint.Y, 0), new Point3d(corridorLine.Line.EndPoint.X, corridorLine.Line.EndPoint.Y, 0))); } var finalPoints = FittingAlgorithm.GetOutlinePoints(unitDepth, hallWidth, mainCorridorObject); var boundaryPointList = new List <Point3d>(); foreach (var point in finalPoints) { boundaryPointList.Add(new Point3d(point.X, point.Y, 0)); } var planBoundary = new PolylineCurve(boundaryPointList); boundary = planBoundary; var percentMixFinal = new List <double> { }; foreach (var buildingMix in currentPercentage) { percentMixFinal.Add(buildingMix.Value); } percentMix = percentMixFinal; }