Пример #1
0
    def __create_src_map( self, commodity, from_secs, from_amount, mob_limit ):
        """ create  source sectors dictionary """
        result = {}
        for sect in from_secs.values() :
            coords  = empSector.to_coord( sect )
            if empSector.is_movable_from( sect, commodity ) :

                mob    = empSector.value( sect, 'mob' ) - mob_limit;
                amount = empSector.value( sect, commodity  ) - from_amount

                if  mob > 0 and amount > 0  :
                    weight = empSector.move_weight( sect, commodity )
                    result[ coords ] = ( amount , mob , weight)

                    ## print "src += " + coords.str() + " " + `amount` + " ",
                    ## print `mob` + " " + `weight`
        return result
Пример #2
0
    def __create_src_map(self, commodity, from_secs, from_amount, mob_limit):
        """ create  source sectors dictionary """
        result = {}
        for sect in from_secs.values():
            coords = empSector.to_coord(sect)
            if empSector.is_movable_from(sect, commodity):

                mob = empSector.value(sect, "mob") - mob_limit
                amount = empSector.value(sect, commodity) - from_amount

                if mob > 0 and amount > 0:
                    weight = empSector.move_weight(sect, commodity)
                    result[coords] = (amount, mob, weight)

                    ## print "src += " + coords.str() + " " + `amount` + " ",
                    ## print `mob` + " " + `weight`
        return result
Пример #3
0
    def redraw(self, total=1):
        if not total and not empDb.updateDB.has_key('SECTOR'):
            # Nothing changed.
            return

        # Remove any existing path.
        self.map.drawPath()

        sectors = self.sectors
        if len(sectors) < 2:
            self.lblVar.set("Select sectors with the right mouse button.\n")
            return
        sDB = empDb.megaDB['SECTOR']
        try:
            quantity = empCmd.getMoveQuantity(self.Quantity.get(),
                                              self.commodity, sectors)
        except ValueError:
            msg = "Enter a valid quantity.\n"
            self.pathList = []
            quantity = 0
        else:
            first = sectors[0]
            last = sectors[-1]
            msg = "Move %d %s: (%d,%d has %s)  (%d,%d has %s)\n" % (
                quantity, self.commodity, first[0], first[1], sDB[first].get(
                    self.commodity, "??"), last[0], last[1], sDB[last].get(
                        self.commodity, "??"))

        reverse = quantity < 0
        if reverse:
            sectors = list(sectors)
            sectors.reverse()
            quantity = -quantity

        start = sectors[0]
        sectorList = [start]
        newPathList = []
        for i in range(1, len(sectors)):
            last = sectors[i - 1]
            path = empPath.best_path(last, sectors[i])
            color = "black"

            newPathList.append([last])
            if path is None:
                # No path between the two sectors.
                color = "red"
                start = sectors[i]
                newPathList[-1].append(start)
                newmob = "??"
##  		return
            else:
                # Calculate new mobility.
                db = sDB[last]
                newmob = int(
                    math.floor((db.get('mob', 0) -
                                empSector.move_weight(db, self.commodity) *
                                path.cost * quantity)))
                if newmob < 0:
                    color = "yellow"

                # Turn path into list of sector coordinates.
                for i in path.directions:
                    start = empDb.directionToSector(start, i)
                    sectorList.append(start)
                    newPathList[-1].append(start)

            # Update text description.
            msg = msg + "%d,%d=>%s    " % (last[0], last[1], newmob)

            # Draw path
            apply(self.map.drawPath, tuple(newPathList[-1]), {"fill": color})

        if reverse:
            newPathList.reverse()

        self.pathList = newPathList
        ##  	apply(self.map.drawPath, tuple(sectorList), {"color":color})
        msg = msg + "%d,%d " % sectors[-1]
        self.lblVar.set(msg)
Пример #4
0
    def redraw(self, total=1):
        if not total and not empDb.updateDB.has_key('SECTOR'):
            # Nothing changed.
            return

        # Remove any existing path.
        self.map.drawPath()

        sectors = self.sectors
        if len(sectors) < 2:
            self.lblVar.set("Select sectors with the right mouse button.\n")
            return
        sDB = empDb.megaDB['SECTOR']
        try:
            quantity = empCmd.getMoveQuantity(self.Quantity.get(),
                                              self.commodity, sectors)
        except ValueError:
            msg = "Enter a valid quantity.\n"
            self.pathList = []
            quantity = 0
        else:
            first = sectors[0]
            last = sectors[-1]
            msg = "Move %d %s: (%d,%d has %s)  (%d,%d has %s)\n" % (
                quantity, self.commodity,
                first[0], first[1], sDB[first].get(self.commodity, "??"),
                last[0], last[1], sDB[last].get(self.commodity, "??"))

        reverse = quantity < 0
        if reverse:
            sectors = list(sectors)
            sectors.reverse()
            quantity = -quantity

        start = sectors[0]
        sectorList = [start]
        newPathList = []
        for i in range(1, len(sectors)):
            last = sectors[i-1]
            path = empPath.best_path(last, sectors[i])
            color = "black"

            newPathList.append([last])
            if path is None:
                # No path between the two sectors.
                color = "red"
                start = sectors[i]
                newPathList[-1].append(start)
                newmob = "??"
##  		return
            else:
                # Calculate new mobility.
                db = sDB[last]
                newmob = int(math.floor(
                    (db.get('mob', 0)
                     - empSector.move_weight(db, self.commodity)
                     * path.cost*quantity)))
                if newmob < 0:
                    color = "yellow"

                # Turn path into list of sector coordinates.
                for i in path.directions:
                    start = empDb.directionToSector(start, i)
                    sectorList.append(start)
                    newPathList[-1].append(start)

            # Update text description.
            msg = msg + "%d,%d=>%s    " % (last[0], last[1], newmob)

            # Draw path
            apply(self.map.drawPath, tuple(newPathList[-1]), {"fill":color})

        if reverse:
            newPathList.reverse()

        self.pathList = newPathList
##  	apply(self.map.drawPath, tuple(sectorList), {"color":color})
        msg = msg + "%d,%d " % sectors[-1]
        self.lblVar.set(msg)