コード例 #1
0
        [MultiReturn(new[] { "DeptData", "LeftOverPolys" })]//"CirculationPolys", "OtherDeptMainPoly"
        public static Dictionary <string, object> PlaceDepartments2D(List <DeptData> deptData, List <Polygon2d> buildingOutline, List <double> kpuDepthList, List <double> kpuWidthList,
                                                                     double acceptableWidth, double polyDivision = 8, int designSeed = 50, bool noExternalWall = false,
                                                                     bool unlimitedKPU = true, bool mode3D = false, double totalBuildingHeight = 60, double avgFloorHeight = 15)
        {
            if (polyDivision >= 1 && polyDivision < 30)
            {
                BuildLayout.SPACING = polyDivision; BuildLayout.SPACING2 = polyDivision;
            }
            double          circulationFreq = 8;
            List <DeptData> deptDataInp     = deptData;

            deptData = deptDataInp.Select(x => new DeptData(x)).ToList(); // example of deep copy

            Dictionary <string, object> deptArrangement = new Dictionary <string, object>();
            double count = 0, eps = 5;
            Random rand = new Random();
            bool   deptPlaced = false;
            Random ran = new Random(designSeed);
            bool   stackOptionsDept = deptData[0].StackingOptions;
            bool   stackOptionsProg = deptData[0].ProgramsInDept[0].StackingOptions;

            while (deptPlaced == false && count < BuildLayout.MAXCOUNT)//MAXCOUNT
            {
                double parameter = BasicUtility.RandomBetweenNumbers(ran, 0.9, 0.5);
                if (!stackOptionsDept)
                {
                    parameter = 0;
                }
                //parameter = 0;
                Trace.WriteLine("PLACE DEPT STARTS , Lets arrange dept again ++++++++++++++++ : " + count);
                deptArrangement = BuildLayout.DeptPlacer(deptData, buildingOutline, kpuDepthList, kpuWidthList, acceptableWidth, circulationFreq, designSeed, noExternalWall, unlimitedKPU, stackOptionsDept, stackOptionsProg, parameter);
                if (deptArrangement != null)
                {
                    List <DeptData>          deptDataUpdated = (List <DeptData>)deptArrangement["DeptData"];
                    List <List <Polygon2d> > deptAllPolys    = new List <List <Polygon2d> >();
                    for (int i = 0; i < deptDataUpdated.Count; i++)
                    {
                        deptAllPolys.Add(deptDataUpdated[i].PolyAssignedToDept);
                    }
                    List <Polygon2d> deptPolysTogether = new List <Polygon2d>();
                    for (int i = 0; i < deptAllPolys.Count; i++)
                    {
                        if (ValidateObject.CheckPolyList(deptAllPolys[i]))
                        {
                            deptPolysTogether.AddRange(deptAllPolys[i]);
                        }
                    }

                    if (deptAllPolys.Count > 0)
                    {
                        Trace.WriteLine("dept arrangement not null, lets check further");
                    }
                    for (int i = 0; i < deptAllPolys.Count; i++)
                    {
                        List <Polygon2d> eachDeptPoly = deptAllPolys[i];
                        if (ValidateObject.CheckPolyList(eachDeptPoly))
                        {
                            deptPlaced = true;
                        }
                        else
                        {
                            deptPlaced = false; Trace.WriteLine("dept arrangement bad polys, rejected"); break;
                        }
                        bool orthoResult = ValidateObject.CheckPolygon2dListOrtho(deptPolysTogether, eps);
                        Trace.WriteLine("The poly formed is : " + orthoResult);
                        if (orthoResult)
                        {
                            deptPlaced = true;
                        }
                        else
                        {
                            deptPlaced = false; Trace.WriteLine("dept arrangement non orthogonal, rejected"); break;
                        }
                    }
                }
                else
                {
                    deptPlaced  = false;
                    designSeed += 1;
                    Trace.WriteLine("DeptPlacer returned null, rejected for: " + count);
                }
                count += 1;
                Trace.WriteLine(" EXIT PLACE DEPARTMENTS +++++++++++++++++++++++++++++++++");
            }// end of while loop
            return(deptArrangement);
        }