public void CreateBenchmark(Base global, Benchmark benchmark) { // set benchmark ID string path = Environment.CurrentDirectory; // without bin\Debug path = path.Substring(0, path.Length - 9) + "Resources\\BenchmarkNr.txt"; // global.Verschnittoptimierung.Output.Text = path; benchmark.benchmarkID = Convert.ToInt32(System.IO.File.ReadAllText(path)); // set creationTime benchmark.creationTime = DateTime.Now; // add boards to benchmark for (int i = 0; i < global.Verschnittoptimierung.numberBoards.Value; i++) { Board board = new Board(); board.boardID = i + 1; board.height = Convert.ToInt32(global.Verschnittoptimierung.boardHeight.Value); board.width = Convert.ToInt32(global.Verschnittoptimierung.boardWidth.Value); board.isCollectionBoard = false; board.size = board.height * board.width; benchmark.boardList.Add(board); } // no collection board in benchmark. code can still be useful for creating a solution /* // add collection board to benchmark Board collectionBoard = new Board(); collectionBoard.boardID = BoardList.Count() + 1; collectionBoard.height = Convert.ToInt32(global.Verschnittoptimierung.boardHeight.Value); collectionBoard.width = Convert.ToInt32(global.Verschnittoptimierung.boardWidth.Value); collectionBoard.isCollectionBoard = false; collectionBoard.size = collectionBoard.height * collectionBoard.width; BoardList.Add(collectionBoard); */ }
// creates a basic solution without rects placed, according to the benchmark public void CreateBasicSolution(Base global, Benchmark benchmark) { Solution solution = new Solution(); // set solution ID string path = Environment.CurrentDirectory; // without bin\Debug path = path.Substring(0, path.Length - 9) + "Resources\\SolutionNr.txt"; solution.SolutionID = Convert.ToInt32(System.IO.File.ReadAllText(path)); // set creationTime solution.creationTime = DateTime.Now; // set Benchmark to solution solution.benchmark = benchmark; solution.usedBenchmarkID = benchmark.benchmarkID; // add boards solution.BoardList = new List<Board>(); for (int i = 0; i < benchmark.boardList.Count; i++) { Board board = new Board(); board.boardID = i + 1; board.height = benchmark.boardList[0].height; board.width = benchmark.boardList[0].width; board.isCollectionBoard = false; board.size = board.height * board.width; solution.BoardList.Add(board); } // add collection board Board collectionBoard = new Board(); collectionBoard.boardID = solution.BoardList.Count + 1; collectionBoard.height = benchmark.boardList[0].height; collectionBoard.width = benchmark.boardList[0].width * 2; collectionBoard.isCollectionBoard = true; collectionBoard.size = collectionBoard.height * collectionBoard.width; solution.BoardList.Add(collectionBoard); // add rects to collection board, sorted from largest to smallest and height > width (change these parameters if necessary) // also remove the coordinates from the rects for(int i = 0; i < benchmark.boardList.Count; i++) { for(int j = 0; j < benchmark.boardList[i].RectList.Count; j++) { Rect rect = new Rect(); rect.rectID = benchmark.boardList[i].RectList[j].rectID; rect.size = benchmark.boardList[i].RectList[j].size; if(benchmark.boardList[i].RectList[j].height < benchmark.boardList[i].RectList[j].width) { rect.height = benchmark.boardList[i].RectList[j].width; rect.width = benchmark.boardList[i].RectList[j].height; } else { rect.height = benchmark.boardList[i].RectList[j].height; rect.width = benchmark.boardList[i].RectList[j].width; } rect.edgeLeftUp = new MyPoint(0,0); rect.edgeRightDown = new MyPoint(0,0); collectionBoard.RectList.Add(rect); } } // sort the rects in rect list from largest size to smallest size (new version; old version below) Tools tools = new Tools(); tools.QuickSortRectBySizeDec(0, collectionBoard.RectList.Count - 1, collectionBoard.RectList); // old version, new version = using quicksort /* // sort the rect list List<Rect> rectList = new List<Rect>(); // as long as rects exist while (collectionBoard.RectList.Count > 0) { // search the largest rect (by size), then add to rectList and remove from collectionBoard List Rect largestRect = collectionBoard.RectList[0]; for (int i = 1; i < collectionBoard.RectList.Count; i++) { if(collectionBoard.RectList[i].size > largestRect.size) { largestRect = collectionBoard.RectList[i]; } } rectList.Add(largestRect); collectionBoard.RectList.Remove(largestRect); } collectionBoard.RectList = rectList; */ // add the remaining parameters to solution solution.numberOfRects = collectionBoard.RectList.Count; solution.percentageFilledArea = 0; global.solution = solution; global.emptySolution = tools.CloneSolution(solution); // cl values ClassificationNumbers clNumbers = new ClassificationNumbers(global); clNumbers.GetAndShowAllClassificationNumbers(); }
public void ShowRectsOnCollectionBoard(Board collectionBoard) { }
public double CalculateFilledPercentageBoard(Board board) { int filledArea = 0; for(int i = 0; i < board.RectList.Count; i++) { filledArea += board.RectList[i].size; } return (Convert.ToDouble(filledArea) / Convert.ToDouble(board.size)); }
public Solution CloneSolution(Solution solution) { Solution solutionClone = new Solution(); solutionClone.SolutionID = solution.SolutionID; solutionClone.usedBenchmarkID = solution.usedBenchmarkID; solutionClone.numberOfBoards = solution.numberOfBoards; solutionClone.numberOfRects = solution.numberOfRects; solutionClone.creationTime = solution.creationTime; solutionClone.percentageFilledArea = solution.percentageFilledArea; solutionClone.numberRectsPlaced = solution.numberRectsPlaced; solutionClone.numberRectsLeft = solution.numberRectsLeft; solutionClone.benchmark = solution.benchmark; solutionClone.BoardList = new List<Board>(); for (int i = 0; i < solution.BoardList.Count; i++) { Board board = new Board(); board.boardID = solution.BoardList[i].boardID; board.height = solution.BoardList[i].height; board.width = solution.BoardList[i].width; board.size = solution.BoardList[i].size; board.isCollectionBoard = solution.BoardList[i].isCollectionBoard; board.edgeLeftUp = new MyPoint(); board.edgeLeftUp.x = (solution.BoardList[i].edgeLeftUp != null)? solution.BoardList[i].edgeLeftUp.x : 0; board.edgeLeftUp.y = (solution.BoardList[i].edgeLeftUp != null)? solution.BoardList[i].edgeLeftUp.y : 0; board.edgeRightDown = new MyPoint(); board.edgeRightDown.x = (solution.BoardList[i].edgeRightDown != null) ? solution.BoardList[i].edgeRightDown.x : 0; board.edgeRightDown.y = (solution.BoardList[i].edgeRightDown != null) ? solution.BoardList[i].edgeRightDown.y : 0; for (int j = 0; j < solution.BoardList[i].RectList.Count; j++) { Rect rect = new Rect(); rect.rectID = solution.BoardList[i].RectList[j].rectID; rect.width = solution.BoardList[i].RectList[j].width; rect.height = solution.BoardList[i].RectList[j].height; rect.size = solution.BoardList[i].RectList[j].size; rect.edgeLeftUp = new MyPoint(); rect.edgeLeftUp.x = (solution.BoardList[i].RectList[j].edgeLeftUp != null)? solution.BoardList[i].RectList[j].edgeLeftUp.x : 0; rect.edgeLeftUp.y = (solution.BoardList[i].RectList[j].edgeLeftUp != null)? solution.BoardList[i].RectList[j].edgeLeftUp.y : 0; rect.edgeRightDown = new MyPoint(); rect.edgeRightDown.x = (solution.BoardList[i].RectList[j].edgeRightDown != null)? solution.BoardList[i].RectList[j].edgeRightDown.x : 0; rect.edgeRightDown.y = (solution.BoardList[i].RectList[j].edgeRightDown != null)? solution.BoardList[i].RectList[j].edgeRightDown.y : 0; board.RectList.Add(rect); } solutionClone.BoardList.Add(board); } return solutionClone; }