public RectangleDiagonal(PackingPosition myPosition, PackingShape myShape) { x1 = myPosition.X; y1 = myPosition.Y; x2 = myPosition.X + (myPosition.Rotated ? myShape.Height : myShape.Width) - 1; y2 = myPosition.Y + (myPosition.Rotated ? myShape.Width : myShape.Height) - 1; }
public PackingItem(int width, int height, PackingShape targetBin) : this() { this.Width = width; this.Height = height; this.TargetBin = (PackingShape)targetBin.Clone(); }
public override double EvaluateMove(Permutation permutation, Swap2Move move, PackingShape binShape, ReadOnlyItemList <PackingItem> items) { // uses full evaluation Swap2Manipulator.Apply(permutation, move.Index1, move.Index2); var solution = DecoderParameter.ActualValue.Decode(permutation, binShape, items); return(SolutionEvaluatorParameter.ActualValue.Evaluate(solution)); }
public int CompareTo(PackingShape other) { int result = this.Width.CompareTo(other.Width); if (result == 0) { result = this.Height.CompareTo(other.Height); } return(result); }
public virtual Solution Decode(IntegerVector intVec, PackingShape binShape, IList <PackingItem> items) { var sequenceMatrix = IntegerVectorProblem.GenerateSequenceMatrix(intVec); Solution result = CreateSolution(binShape); //Fill bins according to grouping vector IList <int> remainingIDs = new List <int>(); foreach (var sequence in sequenceMatrix) { remainingIDs = remainingIDs.Concat(sequence).ToList(); result.Bins.Add(CreatePacking(result, ref remainingIDs, items)); } result.UpdateBinPackings(); //Try to put remaining items in existing bins var temp = new List <int>(remainingIDs); foreach (int id in temp) { foreach (BinPacking2D bp in result.Bins) { var position = FindPositionForItem(bp, items[id]); if (position != null) { bp.PackItem(id, items[id], position); remainingIDs.Remove(id); break; } } } //Put still remaining items in new bins while (remainingIDs.Count > 0) { result.Bins.Add(CreatePacking(result, ref remainingIDs, items)); } result.UpdateBinPackings(); // gkronber: original implementation by Helm also updates the encoded solution (TODO) // var newSolution = new int[intVec.Length]; // int binIndex = 0; // foreach (var bp in result.BinPackings) { // foreach (var entry in bp.ItemPositions) // newSolution[entry.Key] = binIndex; // binIndex++; // } // solution.GroupingVector = new IntegerVector(newSolution); return(result); }
public Solution Decode(Permutation permutation, PackingShape binShape, IList <PackingItem> items) { Solution result = new Solution(binShape, useExtremePoints: true, stackingConstraints: false); IList <int> remainingIDs = new List <int>(permutation); while (remainingIDs.Count > 0) { var bp = new BinPacking2D(binShape); bp.ExtremePointBasedPacking(ref remainingIDs, items, stackingConstraints: false); result.Bins.Add(bp); } result.UpdateBinPackings(); return(result); }
protected override Solution CreateSolution(PackingShape binShape) { return(new Solution(binShape, useExtremePoints: true, stackingConstraints: false)); }
protected abstract Solution CreateSolution(PackingShape binShape);
public abstract double EvaluateMove(TSol encodedSolutionCandidate, TMove move, PackingShape binShape, ReadOnlyItemList <PackingItem> items);
protected PackingShape(PackingShape original, Cloner cloner) : base(original, cloner) { }
public RectangleDiagonal(PackingShape myShape) : this(new PackingPosition(0, 0, 0), myShape) { }
private bool Overlaps(PackingPosition myPosition, PackingPosition checkedPosition, PackingShape checkedShape) { return(Overlaps(new RectangleDiagonal(myPosition, this), new RectangleDiagonal(checkedPosition, checkedShape))); }
public override bool Overlaps(PackingPosition myPosition, PackingPosition checkedPosition, PackingShape <PackingPosition> checkedShape) { return(Overlaps(myPosition, checkedPosition, (PackingShape)checkedShape)); }
private bool Encloses(PackingPosition checkedPosition, PackingShape checkedShape) { return(Encloses(new RectangleDiagonal(this), new RectangleDiagonal(checkedPosition, checkedShape))); }
public override bool Encloses(PackingPosition checkedPosition, PackingShape <PackingPosition> checkedShape) { return(Encloses(checkedPosition, (PackingShape)checkedShape)); }