Beispiel #1
0
def next_generation(population, popSize, k, n, c, liste):  # le k de selection
    parents = selection(k, popSize, population)
    newpopulation = crossover_mutation(parents, popSize, n, liste, c)
    populationMuted = []
    for i in newpopulation:
        populationMuted.append(solution(i))
    RSresult = []
    for j in populationMuted:
        copie = []
        copie = j[0]
        #print(j)
        binList = []
        last = 0
        for i in range(len(copie)):
            boite = Bin(i + 1, c)
            for k in range(len(copie[i])):
                thingy = copie[i]
                objecte = Objet(thingy[k], liste[thingy[k] - 1])
                boite.ranger_obj(objecte)
            last += k
            binList.append(boite)
        classrs = RS()
        rs, listeBins = classrs.RS(n, c, j[0], S=binList)
        solutionlist = []
        for a in listeBins:
            solutionlist.append(a.get_objects)
        final = itemsInBox(solutionlist)
        RSresult.append(chromoTo(final, rs))
    return newpopulation  # RSresult
Beispiel #2
0
def first_fit(list_items, max_size):
    """ Returns list of bins with input items inside. """
    list_bins = []
    list_bins.append(Bin(1, max_size))  # Add first empty bin to list

    cptBins = 1
    for item in list_items:
        # Go through bins and try to allocate
        alloc_flag = False

        for bin in list_bins:
            if bin.total_weight + item.weight <= max_size:
                bin.ranger_obj(item)
                alloc_flag = True
                break

        # If item not allocated in bins in list, create new bin
        # and allocate it to it.
        if alloc_flag == False:
            cptBins += 1
            newBin = Bin(cptBins, max_size)
            newBin.ranger_obj(item)
            list_bins.append(newBin)

    # Turn bins into list of items and return
    list_items = []
    for bin in list_bins:
        list_items.append(bin.get_objects)

    return (list_items), len(list_items)  # nombre de boites
Beispiel #3
0
    def Run(self):
        newItems = list(self.Items)
        newBin = Bin(self.Bin.Dx, self.Bin.Dy)

        self.RemoveLargeItems(newItems, newBin)
        self.FilterFrameConfiguration(newItems, newBin)
        self.EnlargeItemsByOrthogonalPacking(newItems, newBin)

        if len(self.Items) > len(newItems):
            print(f"Preprocess removed {len(self.Items) - len(newItems)} items and reduced container area by {self.Bin.Dx * self.Bin.Dy - newBin.Dx * newBin.Dy}.")

        self.PreprocessedItems = newItems
        self.PreprocessBin = newBin
Beispiel #4
0
    def EnlargeItemsByOrthogonalPacking(self, items, bin):
        feasibleThresholdToItemCount = {}
        largestItemThreshold = -1
        largestItemCount = 0

        for p in range(1, math.floor(bin.Dy / 2.0) + 1):
            
            largeItemSubset = []
            smallItemSubset = []
            itemSubset = []

            largeItemDx = 0
            largestSmallItemDx = 0
            
            for i, item in enumerate(items):
                if item.Dy >= bin.Dy - p:
                    largeItemDx += item.Dx

                    itemSubset.append(item)
                    largeItemSubset.append(item)
                    continue

                if item.Dy <= p:
                    largestSmallItemDx = max(largestSmallItemDx, item.Dx)

                    itemSubset.append(item)
                    smallItemSubset.append(item)
                    continue
            
            if len(largeItemSubset) == 0 or len(smallItemSubset) == 0 or len(itemSubset) == 0 or largestSmallItemDx > largeItemDx:
                continue

            reducedBin = Bin(largeItemDx, bin.Dy)
            
            print(f"Preprocess OPP call with {len(itemSubset)} / {len(items)}")

            orthogonalPackingSolver = OrthogonalPackingSolver(itemSubset, reducedBin)
            isFeasible = orthogonalPackingSolver.Solve(False)
            
            if isFeasible:
                if len(itemSubset) > len(largestItemCount):
                    largestItemCount = len(itemSubset)
                    largestItemThreshold = p

                    feasibleThresholdToItemCount[p] = itemSubset

        if largestItemThreshold == -1:
            return

        maximalItemSet = feasibleThresholdToItemCount[largestItemThreshold]
        itemsToRemove = []

        reducedBinDx = 0
        for item in maximalItemSet:
            itemsToRemove.append(item)
            reducedBinDx += item.Dx

        bin.Dx -= reducedBinDx

        for item in itemsToRemove:
            items.remove(item)