Esempio n. 1
0
    def __init__(self):
        self.datasetfromfile = filereader.readFile("data_set/busy_day.in")
        self.gridx = self.datasetfromfile[0]
        self.gridy = self.datasetfromfile[1]
        self.warehouseObjects = self.datasetfromfile[2]
        self.droneCount = self.datasetfromfile[3]
        self.maxCommands = self.datasetfromfile[4]
        self.maxPayload = self.datasetfromfile[5]
        self.orderObjects = self.datasetfromfile[6]
        self.productWeights = self.datasetfromfile[7]

        # Create the drones
        for i in xrange(self.droneCount):
            self.drones.append(
                drone.drone(self.warehouseObjects[0].location,
                            self.maxPayload))

        # Calculate the nearest wearhouse to each order and vise-versa
        type(self.orderObjects)
        for order in self.orderObjects:
            calculatedDistances = []
            for wh in self.warehouseObjects:
                calculatedDistances.append(
                    travelTime(order.location, wh.location))
            order.mywarehouse = self.warehouseObjects[
                calculatedDistances.index(min(calculatedDistances))]
            wh.deliveryPoints.append(order)

        # for wh1 in self.warehouseObjects:
        #     calculatedDistances = []
        #     for wh2 in self.warehouseObjects:
        #         calculatedDistances.append(travelTime(order.location,wh.location)
        #     order.mywarehouse = self.warehouseObjects[calculatedDistances.index(min(calculatedDistances))]

        # wh.excessInventory
        # wh.wishlist
        # for wh1 in self.self.warehouseObjects:
        #     for wh2 in self.self.warehouseObjects:

        self.commandList = list()
        for wh1 in self.warehouseObjects:
            for wh2 in self.warehouseObjects:
                if wh1 == wh2:
                    continue
                for wl in wh1.wishlist:
                    for el in wh2.excessInventory:
                        if wl in el:
                            self.commandList.append(
                                (wh1, wh2, wh1.wishlist.index(wl)))
                            wh2.excessInventory.remove(wl)
                            wh2.allProducts.remove(wl)
                            wh1.wishlist.remove(wl)
                            wh1.allProducts.append(wl)
        print self.commandList
Esempio n. 2
0
    def __init__(self):
        self.datasetfromfile = filereader.readFile("data_set/busy_day.in")
        self.gridx = self.datasetfromfile[0]
        self.gridy = self.datasetfromfile[1]
        self.warehouseObjects = self.datasetfromfile[2]
        self.droneCount = self.datasetfromfile[3]
        self.maxCommands = self.datasetfromfile[4]
        self.maxPayload = self.datasetfromfile[5]
        self.orderObjects = self.datasetfromfile[6]
        self.productWeights = self.datasetfromfile[7]

        # Create the drones
        for i in xrange(self.droneCount):
            self.drones.append(drone.drone(self.warehouseObjects[0].location, self.maxPayload))

        # Calculate the nearest wearhouse to each order and vise-versa
        type(self.orderObjects)
        for order in self.orderObjects:
            calculatedDistances = []
            for wh in self.warehouseObjects:
                calculatedDistances.append(travelTime(order.location,wh.location))
            order.mywarehouse = self.warehouseObjects[calculatedDistances.index(min(calculatedDistances))]
            wh.deliveryPoints.append(order)


        # for wh1 in self.warehouseObjects:
        #     calculatedDistances = []
        #     for wh2 in self.warehouseObjects:
        #         calculatedDistances.append(travelTime(order.location,wh.location)
        #     order.mywarehouse = self.warehouseObjects[calculatedDistances.index(min(calculatedDistances))]


            # wh.excessInventory
            # wh.wishlist
            # for wh1 in self.self.warehouseObjects:
            #     for wh2 in self.self.warehouseObjects:

        self.commandList = list()
        for wh1 in self.warehouseObjects:
            for wh2 in self.warehouseObjects:
                if wh1 == wh2:
                    continue
                for wl in wh1.wishlist:
                    for el in wh2.excessInventory:
                        if wl in el:
                            self.commandList.append((wh1,wh2,wh1.wishlist.index(wl)))
                            wh2.excessInventory.remove(wl)
                            wh2.allProducts.remove(wl)
                            wh1.wishlist.remove(wl)
                            wh1.allProducts.append(wl)
        print self.commandList
def run():
    pop, profit = filereader.readFile();
    plotdata(pop, profit)
    theta=initialTheta()
    c=cost(theta, pop, profit)
    print 'Initial theta0: ', theta[0]
    print 'Initial theta1: ', theta[1]
    print 'Initial cost: ', c
    print 'Learning rate: ', a
    for i in range(1000):
        theta=iterativeBatchGradientDescent(theta, pop, profit, a)
        # plotCost(c, i)
        # c=cost(theta, pop, profit)
        if i % 100 == 0:
            plotLine(theta[1], theta[0])
            print 'Cost iteration: ', (cost(theta, pop, profit), i)
    plotLine(theta[1], theta[0])
    print 'Cost: ', cost(theta, pop, profit)
    print 'Final theta0: ', theta[0]
    print 'Final theta1: ', theta[1]
    plt.show()