public bool checkAddItem(Item i, List <PotentialPoint> supportPoints, double minHeight) { //SHUFFLE if (supportPoints.Any() && this.weightFits(i)) { // supportPoints.sort(Comparator.comparing(PotentialPoint::getY).thenComparing(PotentialPoint::getZ)); // int randomNum = ThreadLocalRandom.current().nextInt(1, 6); for (int j = 0; j < supportPoints.Count; j++) { PotentialPoint supportPoint = supportPoints[j]; i.setBottomLeftFront(supportPoint); if ((!this.itemsOverlapping(i)) && (this.dimensionsFit(i)) && (supportPoint.cornerCheck(i, this, minHeight))) { PotentialPoint cPointXAxis = PotentialPoint.createXAxisPotentialPoint(i, j, supportPoints); PotentialPoint cPointZAxis = PotentialPoint.createZAxisPotentialPoint(i, j, supportPoints); PotentialPoint.addPointToPotentialPoints(cPointXAxis, supportPoints); PotentialPoint.addPointToPotentialPoints(cPointZAxis, supportPoints); if (i.isStackable()) { PotentialPoint cPointYAxis = PotentialPoint.createYAxisPotentialPoint(i, j, supportPoints); PotentialPoint.addPointToPotentialPoints(cPointYAxis, supportPoints); } PotentialPoint cPointXAxisProjectionMax = PotentialPoint.createXAxisPotentialPointProjectionMax(i, j, supportPoints); PotentialPoint.addPointToPotentialPoints(cPointXAxisProjectionMax, supportPoints); /*Remove chosen support point*/ PotentialPoint.usedPotentialPoints.Add(supportPoints[j]); bool removed = supportPoints.Remove(supportPoints[j]); return(true); } } } return(false); }
/** * * @param i * @param supportPoints * @param minHeight * @return */ public bool checkAddItemRevisited(Item i, List <PotentialPoint> supportPoints, double minHeight) { StopwatchTimer.Start("add"); double zone1, zone2, zone3, zone4; zone1 = this.getZonesDepth(); zone2 = zone1 * 2; zone3 = zone1 * 3; zone4 = this.getDepth(); bool weightOk = true; double rnd = StaticRandom.NextDouble(); supportPoints.Sort((x, y) => { if (x.getY() > y.getY()) { return(1); } else if (x.getY() == y.getY()) { return(0); } return(-1); }); if (supportPoints.Any() && this.weightFits(i)) { for (int j = 0; j < supportPoints.Count; j++) { PotentialPoint supportPoint = supportPoints[j]; i.setBottomLeftFront(supportPoint); if (((i.bottomLeftFront.getZ() < zone1) && (this.getZone1Weight() + i.getWeight() > this.maxZone1Weight * (1 + weightSurplusPerameter))) || (((i.bottomLeftFront.z >= zone1) && (i.bottomLeftFront.getZ() < zone2)) && (this.getZone2Weight() + i.getWeight() > this.maxZone2Weight * (1 + weightSurplusPerameter))) || (((i.bottomLeftFront.z >= zone2) && (i.bottomLeftFront.getZ() < zone3)) && (this.getZone3Weight() + i.getWeight() > this.maxZone3Weight * (1 + weightSurplusPerameter))) || (((i.bottomLeftFront.z >= zone3) && (i.bottomLeftFront.getZ() < zone4)) && (this.getZone4Weight() + i.getWeight() > this.maxZone3Weight * (1 + weightSurplusPerameter)))) { weightOk = false; } else { weightOk = true; } if ((!this.itemsOverlapping(i)) && (this.dimensionsFit(i)) && (supportPoint.cornerCheck(i, this, minHeight)) && weightOk) { PotentialPoint cPointXAxis = PotentialPoint.createXAxisPotentialPoint(i, j, supportPoints); PotentialPoint cPointZAxis = PotentialPoint.createZAxisPotentialPoint(i, j, supportPoints); // TEST--------------- if (cPointXAxis.x != 0) { PotentialPoint nspZzero = new PotentialPoint(0, cPointXAxis.y, cPointXAxis.z); PotentialPoint.addPointToPotentialPoints(nspZzero, supportPoints); } PotentialPoint.addPointToPotentialPoints(cPointXAxis, supportPoints); PotentialPoint.addPointToPotentialPoints(cPointZAxis, supportPoints); if (i.isStackable()) { PotentialPoint cPointYAxis = PotentialPoint.createYAxisPotentialPoint(i, j, supportPoints); PotentialPoint.addPointToPotentialPoints(cPointYAxis, supportPoints); int dim = supportPoints.Count; List <PotentialPoint> newList = new List <PotentialPoint>(); double maxSubst; foreach (PotentialPoint sp in supportPoints) { if ((!sp.equals(cPointYAxis)) && sp.getZ() == cPointYAxis.getZ() && sp.getY() == cPointYAxis.getY()) { if (sp.getMaxXAllowed() > cPointYAxis.getMaxXAllowed()) { maxSubst = sp.getMaxXAllowed(); } else { maxSubst = cPointYAxis.getMaxXAllowed(); } PotentialPoint toAdd = new PotentialPoint(sp.getX(), sp.getY(), sp.getZ(), maxSubst, sp.getMaxYAllowed(), sp.getMaxZAllowed()); newList.Add(toAdd); } } foreach (PotentialPoint sp in newList) { // System.err.println("ADDED"); supportPoints.Add(sp); } } PotentialPoint cPointXAxisProjectionMax = PotentialPoint.createXAxisPotentialPointProjectionMax(i, j, supportPoints); PotentialPoint.addPointToPotentialPoints(cPointXAxisProjectionMax, supportPoints); /*°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°*/ /*Remove chosen support point*/ PotentialPoint.usedPotentialPoints.Add(supportPoints[j]); bool removed = supportPoints.Remove(supportPoints[j]); StopwatchTimer.Stop("add"); return(true); } } } StopwatchTimer.Stop("add"); return(false); }