private ProjectManager GetMITResultOfMultiFile(string fileName) { ProjectManager manager = new ProjectManager(); RcpspSolver solve = new RcpspSolver(); solve = RcpspParser.parseMultiProjFile(fileName); ////产生所有可行划分和所有划分组合 solve.generateAllPossiblePartation(); string comb1 = "(1,2,5)"; string comb2 = "(4)"; string comb3 = "(3)"; solve.EveryCombBestProj[comb1] = RcpspSolver.calCombBestScoreByTabuSearch(comb1, solve.EveryComb[comb1], true); solve.EveryCombBestProj[comb2] = RcpspSolver.calCombBestScoreByTabuSearch(comb2, solve.EveryComb[comb2], true); solve.EveryCombBestProj[comb3] = RcpspSolver.calCombBestScoreByTabuSearch(comb3, solve.EveryComb[comb3], true); //foreach (string str in solve.EveryCombBestProj.Keys) //{ // RcspspProject proj = solve.EveryCombBestProj[str]; // Console.WriteLine("comb core " + str + "is " + proj.BestSocre + " and list is : "); // Console.Write(" "); // foreach (RcpspJob job in proj.Jobs) // { // Console.Write("(" + job.id + "__" + job.project + "__" + job.duration + ")"); // } // Console.WriteLine(); //} List <List <RcspspProject> > projectPartition = new List <List <RcspspProject> >(); projectPartition.Add(solve.EveryComb[comb1]); projectPartition.Add(solve.EveryComb[comb2]); projectPartition.Add(solve.EveryComb[comb3]); RcspspProject bestproj = RcpspSolver.calPartitionBestScoreByTabuSearch(projectPartition, solve.EveryCombBestProj, true); //Console.WriteLine("best core is " + bestproj.BestSocre + " and partition is " + bestproj.BestCombStr); //foreach (RcpspJob job in bestproj.Jobs) //{ // //Console.Write("[" + job.id + "__" + job.project + "__" + job.startTime+"__"+job.duration + "]"); // if (job.isWX) // { // RcspspProject wxProject = solve.EveryCombBestProj[job.project]; // foreach (RcpspJob wxJob in wxProject.Jobs) // { // addJob2Dic(solve.ProjectList, wxJob, job.startTime); // } // } // else // { // addJob2Dic(solve.ProjectList, job); // } //} ////TabuSearch.printGUI(bestproj.Jobs); //Console.WriteLine("total time is " + TabuSearch.calScheduleCore(bestproj.Jobs, false)); //foreach (RcspspProject proj in solve.ProjectList) //{ // Console.WriteLine("Project " + proj.ProjectId); // foreach (RcpspJob projJob in proj.Jobs) // { // Console.WriteLine(projJob.id + "\t" + projJob.startTime + "\t" + (projJob.startTime + projJob.duration)); // } //} //RcspspProject bestproj = solve.calAllPartitionScore(); if (bestproj == null) { return(null); } else { //构造manager Dictionary <RcpspJob, Task> job2Task = new Dictionary <RcpspJob, Task>(); foreach (RcpspJob job in bestproj.Jobs) { if (job.isVirtual) { continue; } Task task = new Task(); if (job.isWX) { task.Name = "****Project " + job.project + " Duration:" + job.duration; } else { task.Name = "(Project:" + job.project + ",Job:" + (Convert.ToInt32(job.id) - 1) + ",Duration:" + job.duration + ")"; } manager.Add(task); manager.SetDuration(task, Convert.ToInt32(job.duration)); manager.SetStart(task, Convert.ToInt32(job.startTime)); job2Task.Add(job, task); //foreach (RcpspJob predJob in job.predecessors) { // //处理紧前关系,建立连接关系 // if (predJob.isVirtual) continue; // if (job2Task.Keys.Contains(predJob)) // manager.Relate(job2Task[predJob],task); //} //处理坞修内任务,形成一个group if (job.isWX) { double iStartTime = job.startTime; manager.SetComplete(task, 1); LinkedList <RcpspJob> wxJobs = solve.EveryCombBestProj[job.project].Jobs; foreach (RcpspJob wxJob in wxJobs) { if (wxJob.isVirtual) { continue; } Task wxTask = new Task(); wxTask.Name = "(Project:" + wxJob.project + ",Job:" + (Convert.ToInt32(wxJob.id) - 1) + ",Duration:" + wxJob.duration + ")"; job2Task.Add(wxJob, wxTask); manager.Add(wxTask); manager.Group(task, wxTask); manager.SetDuration(wxTask, Convert.ToInt32(wxJob.duration)); manager.SetStart(wxTask, Convert.ToInt32(wxJob.startTime + iStartTime)); manager.SetComplete(wxTask, 1); } } } } return(manager); }
static void Main(string[] args) { //Dictionary<string, int> did = new Dictionary<string, int>(); //did.Add("sad", 11); //Console.WriteLine("d is " + did["sad"] + " and d1 is " + did["sad1"]); //int i = 1023; //int j = i / 100; //int k = i % 100; //Console.WriteLine("d is " + i / 100 + " and d1 is " + k); //string fileName = args[0]; string fileName = "G:\\Projects\\VS2012\\算例\\000.mp";//args[0]; RcpspSolver solve = new RcpspSolver(); solve = RcpspParser.parseMultiProjFile(fileName); allMIT(solve); return; //solve.TotalWuWeight = 30; ////产生所有可行划分和所有划分组合 solve.generateAllPossiblePartation(); ////计算所有组合的最优时间和最优分组 solve.calcAllCombMultiProcess(); foreach (string str in solve.EveryCombBestProj.Keys) { RcspspProject proj = solve.EveryCombBestProj[str]; Console.WriteLine("comb core " + str + "is " + proj.BestSocre + " and list is : "); Console.Write(" "); foreach (RcpspJob job in proj.Jobs) { Console.Write("(" + job.id + "__" + job.project + "__" + job.duration + ")"); } Console.WriteLine(); } RcspspProject bestproj = solve.calAllPartitionScore(); Console.WriteLine("all project end time is "); foreach (RcspspProject proj in solve.ProjectList) { if (proj.Jobs.Count > 1) { RcpspJob lastJob = proj.Jobs.Last.Previous.Value; Console.Write(" " + (lastJob.startTime + lastJob.duration)); } } Console.WriteLine(); Console.WriteLine("best core is " + bestproj.BestSocre + " and partition is " + bestproj.BestCombStr); Console.Write("this List is : "); foreach (RcpspJob job in bestproj.Jobs) { //Console.Write("[" + job.id + "__" + job.project + "__" + job.startTime+"__"+job.duration + "]"); if (job.isWX) { RcspspProject wxProject = solve.EveryCombBestProj[job.project]; foreach (RcpspJob wxJob in wxProject.Jobs) { addJob2Dic(solve.ProjectList, wxJob, job.startTime); } } else { addJob2Dic(solve.ProjectList, job); } } //TabuSearch.printGUI(bestproj.Jobs); Console.WriteLine("total time is " + TabuSearch.calScheduleCore(bestproj.Jobs, true)); foreach (RcspspProject proj in solve.ProjectList) { Console.WriteLine("Project " + proj.ProjectId); foreach (RcpspJob projJob in proj.Jobs) { Console.WriteLine(projJob.id + "\t" + projJob.startTime + "\t" + (projJob.startTime + projJob.duration)); } } return; }
private ProjectManager GetResultOfMultiFile(string fileName) { ProjectManager manager = new ProjectManager(); RcpspSolver solve = new RcpspSolver(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); solve = RcpspParser.parseMultiProjFile(fileName); stopWatch.Stop(); long parseTime = stopWatch.ElapsedMilliseconds; stopWatch.Reset(); stopWatch.Start(); ////产生所有可行划分和所有划分组合 solve.generateAllPossiblePartation(); ////计算所有组合的最优时间和最优分组 solve.calcAllCombMultiProcess(); RcspspProject bestproj = solve.calAllPartitionScore(); stopWatch.Stop(); long calcTime = stopWatch.ElapsedMilliseconds; if (bestproj == null) { return(null); } else { //构造manager Dictionary <RcpspJob, Task> job2Task = new Dictionary <RcpspJob, Task>(); foreach (RcpspJob job in bestproj.Jobs) { if (job.isVirtual) { continue; } Task task = new Task(); if (job.isWX) { task.Name = "****Project " + job.project + " Duration:" + job.duration; } else { task.Name = "(Project:" + job.project + ",Job:" + (Convert.ToInt32(job.id) - 1) + ",Duration:" + job.duration + ")"; } manager.Add(task); manager.SetDuration(task, Convert.ToInt32(job.duration)); manager.SetStart(task, Convert.ToInt32(job.startTime)); job2Task.Add(job, task); //foreach (RcpspJob predJob in job.predecessors) { // //处理紧前关系,建立连接关系 // if (predJob.isVirtual) continue; // if (job2Task.Keys.Contains(predJob)) // manager.Relate(job2Task[predJob],task); //} //处理坞修内任务,形成一个group if (job.isWX) { double iStartTime = job.startTime; manager.SetComplete(task, 1); LinkedList <RcpspJob> wxJobs = solve.EveryCombBestProj[job.project].Jobs; foreach (RcpspJob wxJob in wxJobs) { if (wxJob.isVirtual) { continue; } Task wxTask = new Task(); wxTask.Name = "(Project:" + wxJob.project + ",Job:" + (Convert.ToInt32(wxJob.id) - 1) + ",Duration:" + wxJob.duration + ")"; job2Task.Add(wxJob, wxTask); manager.Add(wxTask); manager.Group(task, wxTask); manager.SetDuration(wxTask, Convert.ToInt32(wxJob.duration)); manager.SetStart(wxTask, Convert.ToInt32(wxJob.startTime + iStartTime)); manager.SetComplete(wxTask, 1); //遍历建立关系 //foreach (RcpspJob predwxJob in wxJob.predecessors) { // //处理紧前关系,建立连接关系 // if (predwxJob.isVirtual) continue; // if (job2Task.Keys.Contains(predwxJob)) // //manager.Relate(job2Task[predwxJob], wxTask); //} } } } } MessageBox.Show("最高得分:" + bestproj.BestSocre + ",文件解析耗时:" + parseTime + "ms,计算耗时:" + calcTime + "ms,最大并发数量:" + System.Threading.Tasks.TaskScheduler.Default.MaximumConcurrencyLevel, "Gantt Chart", MessageBoxButtons.OK, MessageBoxIcon.Information); return(manager); }