/// <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)); }
/////////////////////////////////////////////////////////////////// /// 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)); }
internal static Dictionary <string, object> FindPreferredProgs(double circulationFactor = 1, int caseStudy = 0, string programDocumentPath = "", bool stackingOptionsProg = false) { 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 <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[6]); progTypeList.Add(values[7]); progAdjList.Add(values[8]); List <Cell> dummyCell = new List <Cell> { new Cell(Point2d.ByCoordinates(0, 0), 0, 0, 0, true) }; 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, values[7], stackingOptionsProg); // prev multipled circulationfactor with unit area of prog programDataStack.Add(progData); }// end of for each statement List <string> progAdjId = new List <string>(); for (int i = 0; i < progIdList.Count; i++) { string adjacency = progAdjList[i]; List <string> adjList = adjacency.Split('.').ToList(); progAdjId.AddRange(adjList); } List <string> strList = new List <string>(); List <int> numIdList = new List <int>(); for (int i = 0; i < progAdjId.Count; i++) { strList.Add(progAdjId[i]); int value = 0; try { value = Int32.Parse(progAdjId[i]); } catch { value = (int)BasicUtility.RandomBetweenNumbers(new Random(i), progAdjId.Count - 1, 0); } numIdList.Add(value); progAdjId[i] = value.ToString(); } List <double> adjWeightList = new List <double>(); for (int i = 0; i < progIdList.Count; i++) { int count = 0; for (int j = 0; j < progAdjId.Count; j++) { if (i == numIdList[j]) { count += 1; } } adjWeightList.Add(count); } adjWeightList = BasicUtility.NormalizeList(adjWeightList, 0, 10); string x = ""; return(new Dictionary <string, object> { { "ProgIdList", (progIdList) }, { "ProgramList", (programList) }, { "DeptNameList", (deptNameList) }, { "ProgQuantList", (progQuantList) }, { "AreaEachProgList", (areaEachProgList) }, { "ProgPrefValList", (prefValProgList) }, { "ProgAdjList", (progAdjList) }, { "ProgAdjWeightList", (adjWeightList) } }); }
internal static Dictionary <string, object> FindPreferredDepts(double circulationFactor = 1, int caseStudy = 0, string programDocumentPath = "", bool stackingOptionsProg = false) { 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 <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]); progTypeList.Add(values[7]); progAdjList.Add(values[8]); List <Cell> dummyCell = new List <Cell> { new Cell(Point2d.ByCoordinates(0, 0), 0, 0, 0, true) }; 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, values[7], stackingOptionsProg); // prev multipled circulationfactor with unit area of prog programDataStack.Add(progData); }// end of for each statement List <List <string> > deptTopList = MakeDeptTopology(progAdjList); List <List <string> > deptNameAdjacencyList = new List <List <string> >(); string kpuDeptName = ""; int kpuIndex = 0; for (int i = 0; i < deptTopList.Count; i++) { if (progTypeList[i].IndexOf(BuildLayout.KPU.ToLower()) != -1 || progTypeList[i].IndexOf(BuildLayout.KPU.ToUpper()) != -1) { kpuDeptName = deptNameList[i]; break; } } for (int i = 0; i < deptTopList.Count; i++) { bool kpuFound = false; List <string> deptNameAdjacency = new List <string>(); for (int j = 0; j < deptTopList[i].Count; j++) { string str = deptTopList[i][j]; if (str.Count() < 1 || str == "" || str == " " || str == "\r") { str = (i + j).ToString(); } string depName = deptNameList[Convert.ToInt16(str)]; deptNameAdjacency.Add(depName); } deptNameAdjacencyList.Add(deptNameAdjacency); }// end of for loop List <string> deptNames = GetDeptNames(deptNameList); for (int i = 0; i < deptNames.Count; i++) { if (deptNames[i] == kpuDeptName) { kpuIndex = i; break; } } List <List <string> > NumberOfDeptNames = new List <List <string> >(); List <List <string> > NumberOfDeptTop = new List <List <string> >(); for (int i = 0; i < deptNames.Count; i++) { List <string> numDeptnames = new List <string>(); List <string> numDeptTop = new List <string>(); for (int j = 0; j < deptNameList.Count; j++) { if (deptNames[i] == deptNameList[j]) { numDeptnames.AddRange(deptNameAdjacencyList[j]); numDeptTop.AddRange(deptTopList[j]); } } NumberOfDeptNames.Add(numDeptnames); NumberOfDeptTop.Add(numDeptTop); }// end of for loop statement for (int i = 0; i < NumberOfDeptNames.Count; i++) { NumberOfDeptNames[i].RemoveAll(x => x == deptNames[i]); NumberOfDeptNames[i].RemoveAll(x => x == kpuDeptName); if (i == kpuIndex) { NumberOfDeptNames[i].Clear(); } } List <string> mostFreq = new List <string>(); for (int i = 0; i < NumberOfDeptNames.Count; i++) { var most = ""; if (NumberOfDeptNames[i].Count == 0) { most = ""; } else { most = (from item in NumberOfDeptNames[i] group item by item into g orderby g.Count() descending select g.Key).First(); } mostFreq.Add(most); } var frequency = mostFreq.GroupBy(x => x).OrderByDescending(x => x.Count()).ToList(); List <string> depImpList = new List <string>(); for (int i = 0; i < frequency.Count(); i++) { depImpList.AddRange(frequency[i]); } depImpList = depImpList.Distinct().ToList(); for (int i = 0; i < depImpList.Count(); i++) { depImpList.Remove(""); } return(new Dictionary <string, object> { { "ProgIdList", (progIdList) }, { "ProgramList", (programList) }, { "DeptNameList", (deptNameList) }, { "ProgQuantList", (progQuantList) }, { "AreaEachProgList", (areaEachProgList) }, { "ProgPrefValList", (prefValProgList) }, { "ProgAdjList", (progAdjList) }, { "DeptTopoList", (deptTopList) }, { "DeptTopoAdjacency", (deptNameAdjacencyList) }, { "EachDeptAdjDeptList", (NumberOfDeptNames) }, { "DeptTopListTotal", (NumberOfDeptTop) }, { "DeptNamesUnique", (deptNames) }, { "MostFrequentDept", (mostFreq) }, { "MostFrequentDeptSorted", (depImpList) } }); }