コード例 #1
0
 // constructor for container node
 internal Node(int id, NodeType type)
 {
     _id           = id;
     _nodeType     = type;
     _check        = false;
     _poly         = null;
     _parent       = null;
     _deptAssigned = null;
 }
コード例 #2
0
 internal Node(int id, Node parent, Node left, Node right, NodeType type, Polygon2d poly, Line2d splitLine, DeptData dept)
 {
     _id           = id;
     _left         = left;
     _right        = right;
     _parent       = parent;
     _nodeType     = type;
     _deptAssigned = dept;
     _poly         = poly;
     _splitLine    = splitLine;
     _check        = false;
 }
コード例 #3
0
        // constructor for root node
        internal Node(int id, NodeType type, bool flag, Point centerPt, double radius)
        {
            _id                 = id;
            _poly               = null;
            _nodeType           = type;
            _parent             = null;
            _deptAssigned       = null;
            _check              = false;
            _isRoot             = flag;
            _centerPt           = centerPt;
            _radius             = radius;
            _radiusForContainer = _radius / _prop;

            if (type == NodeType.Container)
            {
                _extraRadius = _radius + _radiusForContainer;
            }
        }
コード例 #4
0
        //sorts a program data inside dept data based on PREFERENCEPOINT
        internal static List <DeptData> SortProgramsByPrefInDept(List <DeptData> deptDataInp, bool stackingOptions = false, int designSeed = 0)
        {
            double weight = 1; //

            if (deptDataInp == null)
            {
                return(null);
            }
            List <DeptData> deptData = deptDataInp.Select(x => new DeptData(x)).ToList(); // example of deep copy

            //for (int i = 0; i < deptDataInp.Count; i++) deptData.Add(new DeptData(deptDataInp[i]));
            double eps = 01, inc = 0.01;

            for (int i = 0; i < deptData.Count; i++)
            {
                DeptData           deptItem          = deptData[i];
                List <ProgramData> sortedProgramData = new List <ProgramData>();
                List <ProgramData> progItems         = deptItem.ProgramsInDept;
                SortedDictionary <double, ProgramData> sortedPrograms = new SortedDictionary <double, ProgramData>();
                List <double> keys = new List <double>();
                for (int j = 0; j < progItems.Count; j++)
                {
                    double key = progItems[j].ProgPreferenceVal + eps + weight * progItems[j].AdjacencyWeight;
                    //double key = progItems[j].ProgPreferenceVal + eps;
                    try { sortedPrograms.Add(key, progItems[j]); }
                    catch { Random rand = new Random(j);  key += rand.NextDouble(); }
                    progItems[j].ProgramCombinedAdjWeight = key;
                    eps += inc;
                }
                eps = 0;
                foreach (KeyValuePair <double, ProgramData> p in sortedPrograms)
                {
                    sortedProgramData.Add(p.Value);
                }
                sortedProgramData.Reverse();

                //if (stackingOptions) sortedProgramData = RandomizeProgramList(sortedProgramData,designSeed);
                deptItem.ProgramsInDept = sortedProgramData;
            }
            List <DeptData> newDept = deptData.Select(x => new DeptData(x)).ToList(); // example of deep copy

            return(newDept);
        }
コード例 #5
0
        public static Dictionary <string, object> PlacePrograms2D(List <DeptData> deptData, List <double> kpuProgramWidthList, double minAllowedDim = 5, int designSeed = 5, bool checkAspectRatio = false)
        {
            if (deptData == null)
            {
                return(null);
            }
            List <DeptData> deptDataInp = deptData;

            deptData = deptDataInp.Select(x => new DeptData(x)).ToList(); // example of deep copy
            List <List <Polygon2d> > polyPorgsAdded = new List <List <Polygon2d> >();
            List <ProgramData>       progDataNew    = new List <ProgramData>();

            for (int i = 0; i < deptData.Count; i++)
            {
                DeptData deptItem = deptData[i];
                //if (i == 0)
                if ((deptItem.DepartmentType.IndexOf(BuildLayout.KPU.ToLower()) != -1 ||
                     deptItem.DepartmentType.IndexOf(BuildLayout.KPU.ToUpper()) != -1))
                {
                    Dictionary <string, object> placedPrimaryProg = BuildLayout.PlaceKPUPrograms(deptData[i].PolyAssignedToDept, deptData[i].ProgramsInDept, kpuProgramWidthList);
                    deptData[i].ProgramsInDept = (List <ProgramData>)placedPrimaryProg["ProgramData"];
                }
                else
                {
                    Dictionary <string, object> placedSecondaryProg = BuildLayout.PlaceREGPrograms(deptData[i], minAllowedDim, designSeed, checkAspectRatio);
                    if (placedSecondaryProg != null)
                    {
                        deptData[i].ProgramsInDept = (List <ProgramData>)placedSecondaryProg["ProgramData"];
                    }
                    else
                    {
                        deptData[i].ProgramsInDept = null;
                    }
                }
            }
            List <DeptData> newDeptData = deptData.Select(x => new DeptData(x)).ToList(); // example of deep copy

            return(new Dictionary <string, object>
            {
                { "DeptData", (newDeptData) }
            });
        }
コード例 #6
0
        internal DeptData(DeptData other)
        {
            _deptName                   = other.DepartmentName;
            _progDataList               = other.ProgramsInDept;
            _numCellsDept               = other.NumCellsNeededDept();
            _cirFactor                  = other.DeptCirFactor;
            _deptAreaNeeded             = other.AreaEachDept();
            _deptAreaNeeded             = other.DeptAreaNeeded;
            _numCells                   = other.NumCellsNeededDept();
            _numCellAdded               = other.NumCellsInDept;
            _IsAreaSatisfied            = other.IsAreaSatisfied;
            _CellsAssigned              = other.DepartmentCells;
            _gridX                      = other._gridX;
            _gridY                      = other._gridY;
            _deptType                   = other.DepartmentType;
            _deptAreaProportion         = other.DeptAreaProportionNeeded;
            _deptAreaProportionAchieved = other.DeptAreaProportionAchieved;

            _areaGivenDept       = other.DeptAreaProvided;
            _deptAbrv            = other.DepartmentAbbrev;
            _deptAdjacencyWeight = other.DeptAdjacencyWeight;
            _stackingOptions     = other._stackingOptions;
            _mode3D          = other._mode3D;
            _flrHeightList   = other._flrHeightList;
            _floorLevel      = other.DeptFloorLevel;
            _numDeptPerFloor = other.NumDeptPerFloor;

            if (other.PolyAssignedToDept != null && other.PolyAssignedToDept.Count > 0)
            {
                _polyDepts = other.PolyAssignedToDept;
            }
            else
            {
                _polyDepts = null;
            }
        }
コード例 #7
0
        [MultiReturn(new[] { "DeptData", "LeftOverPolys" })]//"CirculationPolys", "OtherDeptMainPoly"
        public static Dictionary <string, object> PlaceDepartments3D(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, int numDeptPerFloor = 2)
        {
            Trace.WriteLine("Dept 3d mode");
            List <DeptData> deptDataInp = deptData;

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

            List <double> floorHeightList       = deptDataInp[0].FloorHeightList;
            Dictionary <string, object> deptObj = new Dictionary <string, object>();

            //KPUDept
            //DeptData KPUDept = new DeptData(deptData[0]);
            int  index          = 1;
            bool deptUpperLimit = false;
            List <List <DeptData> > deptRegPerFloorList = new List <List <DeptData> >();

            for (int i = 0; i < floorHeightList.Count; i++)
            {
                List <DeptData> deptInFloor = new List <DeptData>();
                DeptData        KPUDept     = new DeptData(deptData[0]);
                KPUDept.DeptFloorLevel = i;
                deptInFloor.Add(KPUDept);
                if (numDeptPerFloor < 0 || numDeptPerFloor > 4)
                {
                    numDeptPerFloor = 2;
                }
                for (int j = 0; j < numDeptPerFloor; j++)
                {
                    DeptData REGDept = new DeptData(deptData[index]);
                    REGDept.DeptFloorLevel = i;
                    deptInFloor.Add(REGDept);
                    index += 1;
                    //if (index > deptData.Count-1) { deptUpperLimit = true; break; }
                    if (index > deptData.Count - 1)
                    {
                        index = 1;
                    }
                }
                deptRegPerFloorList.Add(deptInFloor);
                //if (deptUpperLimit) break;
            }

            List <DeptData> deptAll = new List <DeptData>();

            for (int i = 0; i < floorHeightList.Count; i++)
            {
                // replaced deptData with deptRegPerFloorList[i]
                deptObj = PlaceDepartments2D(deptRegPerFloorList[i], buildingOutline, kpuDepthList, kpuWidthList, acceptableWidth,
                                             polyDivision, designSeed, noExternalWall);
                List <DeptData> deptDataList = (List <DeptData>)deptObj["DeptData"];
                //for (int j = 0; j < deptDataList.Count; j++) { deptDataList[j].DeptFloorLevel = i; }
                List <DeptData> depInObj = deptDataList.Select(x => new DeptData(x)).ToList(); // example of deep copy
                deptObj["DeptData"] = depInObj;
                deptAll.AddRange(depInObj);
            }
            deptObj["DeptData"] = deptAll;
            //string test = "";
            return(deptObj);
        }
コード例 #8
0
        /// <summary>
        /// Make the data stack from the string node
        /// </summary>
        /// <param name="circulationFactor"></param>
        /// <param name="programDocumentString"></param>
        /// <param name="stackingOptionsDept"></param>
        /// <param name="stackingOptionsProg"></param>
        /// <param name="designSeed"></param>
        /// <returns name ="DeptData"> List of Dept Data Object"</returns>
        public static List <DeptData> MakeDataStackFromString(double circulationFactor = 1, string programDocumentString = "", bool stackingOptionsDept = false, bool stackingOptionsProg = false, int designSeed = 0)
        {
            double        dim = 5;
            StreamReader  reader;
            List <string> progIdList       = new List <string>();
            List <string> programList      = new List <string>();
            List <string> deptNameList     = new List <string>();
            List <string> progQuantList    = new List <string>();
            List <string> areaEachProgList = new List <string>();
            List <string> prefValProgList  = new List <string>();
            List <string> progAdjList      = new List <string>();
            List <string> progTypeList     = new List <string>();
            List <string> deptIdList       = new List <string>();
            List <string> deptAdjList      = new List <string>();

            List <List <string> > dataStack        = new List <List <string> >();
            List <ProgramData>    programDataStack = new List <ProgramData>();
            Stream res;

            int readCount = 0;

            string[] csvText = programDocumentString.Split('\n');
            //Trace.WriteLine(csvText);
            foreach (string s in csvText)
            {
                if (s.Length == 0)
                {
                    continue;
                }
                var values = s.Split(',');
                if (readCount == 0)
                {
                    readCount += 1; continue;
                }
                progIdList.Add(values[0]);
                programList.Add(values[1]);
                deptNameList.Add(values[2]);
                progQuantList.Add(values[3]);
                prefValProgList.Add(values[5]);
                progTypeList.Add(values[7]);
                progAdjList.Add(values[8]);
                deptIdList.Add(values[9]);
                deptAdjList.Add(values[10]);
                List <Cell> dummyCell = new List <Cell> {
                    new Cell(Point2d.ByCoordinates(0, 0), 0, 0, 0, true)
                };
                //List<string> adjList = new List<string>();
                //adjList.Add(values[8]);
                ProgramData progData = new ProgramData(Convert.ToInt32(values[0]), values[1], values[2], Convert.ToInt32(Convert.ToDouble(values[3])),
                                                       Convert.ToDouble(values[4]), Convert.ToInt32(values[6]), progAdjList, dummyCell, dim, dim, Convert.ToString(values[7]), stackingOptionsProg); // prev multipled circulationfactor with unit area of prog
                programDataStack.Add(progData);
            } // end of for each statement

            List <string> deptIdSequenced  = new List <string>();
            List <string> deptAdjSequenced = new List <string>();
            List <string> deptNames        = GetDeptNames(deptNameList);

            for (int i = 0; i < deptNames.Count; i++)
            {
                for (int j = 0; j < deptNameList.Count; j++)
                {
                    if (deptNames[i].ToLower().IndexOf(deptNameList[j].ToLower()) != -1)
                    {
                        deptIdSequenced.Add(deptIdList[j]);
                        deptAdjSequenced.Add(deptAdjList[j]);
                        break;
                    }
                }
            }

            List <DeptData>             deptDataStack    = new List <DeptData>();
            Dictionary <string, object> progAdjWeightObj = FindPreferredProgs(progIdList, progAdjList);
            List <double> adjWeightList = (List <double>)progAdjWeightObj["ProgAdjWeightList"];

            for (int i = 0; i < deptNames.Count; i++)
            {
                List <ProgramData> progInDept = new List <ProgramData>();
                for (int j = 0; j < programDataStack.Count; j++)
                {
                    if (deptNames[i] == programDataStack[j].DeptName)
                    {
                        programDataStack[j].AdjacencyWeight = adjWeightList[j];
                        progInDept.Add(programDataStack[j]);
                    }
                }
                List <ProgramData> programBasedOnQuanity = MakeProgramListBasedOnQuantity(progInDept);
                DeptData           dept = new DeptData(deptNames[i], programBasedOnQuanity, circulationFactor, dim, dim, stackingOptionsDept);
                deptDataStack.Add(dept);
            } // end of for loop statement
            Dictionary <string, object> programDocObj = FindPreferredDepts(deptNameList, progTypeList, progAdjList);
            List <string> preferredDept = (List <string>)programDocObj["MostFrequentDeptSorted"];

            //sort the depts by high area
            deptDataStack = SortDeptData(deptDataStack, preferredDept);

            //added to compute area percentage for each dept
            double totalDeptArea = 0;

            for (int i = 0; i < deptDataStack.Count; i++)
            {
                totalDeptArea += deptDataStack[i].DeptAreaNeeded;
            }
            for (int i = 0; i < deptDataStack.Count; i++)
            {
                deptDataStack[i].DeptAreaProportionNeeded = Math.Round((deptDataStack[i].DeptAreaNeeded / totalDeptArea), 3);
            }

            return(SortProgramsByPrefInDept(deptDataStack, stackingOptionsProg, designSeed));
        }
コード例 #9
0
        ///////////////////////////////////////////////////////////////////
        /// NOTE: This project requires REFERENCEPOINTs to the ProtoInterface
        /// and ProtoGeometry DLLs. These are found in the Dynamo install
        /// directory.
        ///////////////////////////////////////////////////////////////////

        #region - Public Methods
        //read embedded .csv file and make data stack
        /// <summary>
        /// Builds the data stack from the embedded program document.
        /// Returns the Dept Data object
        /// </summary>
        /// <param name="dimX">x axis dimension of the grid.</param>
        /// <param name="dimY">y axis dimension of the grid.</param>
        /// <param name="circulationFactor">Multiplier to account for add on circulation area.</param>
        /// <returns name="DeptData">List of department data object from the provided program document.</returns>
        /// <search>
        /// make data stack, dept data object, program data object
        /// </search>
        public static List <DeptData> MakeDataStack(double circulationFactor = 1, int caseStudy = 0, string programDocumentPath = "", bool stackingOptionsDept = false, bool stackingOptionsProg = false, int designSeed = 0)
        {
            double        dim = 5;
            StreamReader  reader;
            List <string> progIdList       = new List <string>();
            List <string> programList      = new List <string>();
            List <string> deptNameList     = new List <string>();
            List <string> progQuantList    = new List <string>();
            List <string> areaEachProgList = new List <string>();
            List <string> prefValProgList  = new List <string>();
            List <string> progAdjList      = new List <string>();

            List <List <string> > dataStack        = new List <List <string> >();
            List <ProgramData>    programDataStack = new List <ProgramData>();
            Stream res;

            if (programDocumentPath == "")
            {
                //string[] csvText = Properties.Resources.PROGRAMCSV.Split('\n');
                if (caseStudy == 1)
                {
                    res = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("SpacePlanning.src.Asset.MayoProgram_1.csv");
                }
                else if (caseStudy == 2)
                {
                    res = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("SpacePlanning.src.Asset.OtherProgram.csv");
                }
                else if (caseStudy == 3)
                {
                    res = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("SpacePlanning.src.Asset.ProgramDocument_Reg.csv");
                }
                else if (caseStudy == 4)
                {
                    res = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("SpacePlanning.src.Asset.OtherProgram.csv");
                }
                else if (caseStudy == 5)
                {
                    res = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("SpacePlanning.src.Asset.MULTIDEPT.csv");
                }
                else
                {
                    res = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("SpacePlanning.src.Asset.ProgramDocument.csv");
                }

                reader = new StreamReader(res);
            }
            else
            {
                reader = new StreamReader(File.OpenRead(@programDocumentPath));
            }
            int readCount = 0;


            //StreamReader reader = new StreamReader(res);
            string docInfo = reader.ReadToEnd();

            string[] csvText = docInfo.Split('\n');
            Trace.WriteLine(csvText);
            foreach (string s in csvText)
            {
                if (s.Length == 0)
                {
                    continue;
                }
                var values = s.Split(',');
                if (readCount == 0)
                {
                    readCount += 1; continue;
                }
                progIdList.Add(values[0]);
                programList.Add(values[1]);
                deptNameList.Add(values[2]);
                progQuantList.Add(values[3]);
                prefValProgList.Add(values[5]);
                progAdjList.Add(values[8]);
                List <Cell> dummyCell = new List <Cell> {
                    new Cell(Point2d.ByCoordinates(0, 0), 0, 0, 0, true)
                };
                //List<string> adjList = new List<string>();
                //adjList.Add(values[8]);
                ProgramData progData = new ProgramData(Convert.ToInt32(values[0]), values[1], values[2], Convert.ToInt32(Convert.ToDouble(values[3])),
                                                       Convert.ToDouble(values[4]), Convert.ToInt32(values[6]), progAdjList, dummyCell, dim, dim, Convert.ToString(values[7]), stackingOptionsProg); // prev multipled circulationfactor with unit area of prog
                programDataStack.Add(progData);
            }// end of for each statement

            List <string>               deptNames        = GetDeptNames(deptNameList);
            List <DeptData>             deptDataStack    = new List <DeptData>();
            Dictionary <string, object> progAdjWeightObj = FindPreferredProgs(circulationFactor = 1, caseStudy = 0, programDocumentPath, stackingOptionsProg);
            List <double>               adjWeightList    = (List <double>)progAdjWeightObj["ProgAdjWeightList"];

            for (int i = 0; i < deptNames.Count; i++)
            {
                List <ProgramData> progInDept = new List <ProgramData>();
                for (int j = 0; j < programDataStack.Count; j++)
                {
                    if (deptNames[i] == programDataStack[j].DeptName)
                    {
                        programDataStack[j].AdjacencyWeight = adjWeightList[j];
                        progInDept.Add(programDataStack[j]);
                    }
                }
                List <ProgramData> programBasedOnQuanity = MakeProgramListBasedOnQuantity(progInDept);
                DeptData           dept = new DeptData(deptNames[i], programBasedOnQuanity, circulationFactor, dim, dim, stackingOptionsDept);
                deptDataStack.Add(dept);
            }// end of for loop statement
            Dictionary <string, object> programDocObj = FindPreferredDepts(circulationFactor, caseStudy, programDocumentPath, stackingOptionsDept);
            List <string> preferredDept = (List <string>)programDocObj["MostFrequentDeptSorted"];

            //sort the depts by high area
            deptDataStack = SortDeptData(deptDataStack, preferredDept);

            //added to compute area percentage for each dept
            double totalDeptArea = 0;

            for (int i = 0; i < deptDataStack.Count; i++)
            {
                totalDeptArea += deptDataStack[i].DeptAreaNeeded;
            }
            for (int i = 0; i < deptDataStack.Count; i++)
            {
                deptDataStack[i].DeptAreaProportionNeeded = Math.Round((deptDataStack[i].DeptAreaNeeded / totalDeptArea), 3);
            }

            return(SortProgramsByPrefInDept(deptDataStack, stackingOptionsProg, designSeed));
        }