Exemplo n.º 1
0
    def hireIfProfit(self):

        # workers do not hire
        if self.agType == "workers":
            return

        if self.profit <= common.hiringThreshold:
            return

        tmpList = []
        for ag in self.agentList:
            if ag != self:
                if ag.agType == "workers" and not ag.employed:
                    tmpList.append(ag)

        if len(tmpList) > 0:
            hired = tmpList[randint(0, len(tmpList) - 1)]

            hired.employed = True
            gvf.colors[hired] = "Aqua"
            gvf.createEdge(self, hired)  # self, here, is the hiring firm

        # count edges (workers) of the firm, after hiring (the values is
        # recorded, but not used directly)
        self.numOfWorkers = gvf.nx.degree(common.g, nbunch=self)
        # nbunch : iterable container, optional (default=all nodes)
        # A container of nodes. The container will be iterated through once.
        print("entrepreneur", self.number, "has", self.numOfWorkers,
              "edge/s after hiring")
Exemplo n.º 2
0
    def searchForSector(self):
        if self.agType != "recipes":
            return

        if not self.canMove:
            return

        step = self.content[0]  # first step to be done

        res = gvf.findNodesFromSector(step)
        if common.verbose:
            if res == []:
                print(
                    "recipe %d cannot find a factory for the step of type %d" %
                    (self.number, step))
        else:
            if common.verbose:
                print(
                    "recipe %d found %d factory/ies for the step of type %d" %
                    (self.number, len(res), step))

        # for debug only!!!!!!!!!!!!!
        # if res!=[]:
        # for aNode in res: print "searchForSector:", aNode.number, aNode.sector
        # else: print "searchForSector: no node for sector", step

        if res != []:
            random.shuffle(res)
            if common.verbose:
                print("recipe %d moving to factory %d" %
                      (self.number, res[0].number))

                # future development: here res[0] simply contain a randomly chosen unit
                # (if in res we have more than a unique possibility)
                # it is possible to put here intelligence (as the effect of the)
                # action of the recipe, searching for data such as production costs of
                # the factories, their waiting lists, their quality standards, their
                # owners, etc.

            # create an edge from self.factoryInWhichRecipeIs to res[0]
            # or upgrading the weight of the link
            if self.factoryInWhichRecipeIs is not None:
                gvf.createEdge(self.factoryInWhichRecipeIs, res[0])
            self.factoryInWhichRecipeIs = res[0]

            # self here is the calling recipe
            res[0].addToRecipeWaitingList(self)
Exemplo n.º 3
0
    def hireFireWithProduction(self):

        # workers do not hire/fire
        if self.agType == "workers":
            return

        # to decide to hire/fire we need to know the number of employees
        # the value is calcutated on the fly, to be sure of accounting for
        # modifications coming from outside
        # (nbunch : iterable container, optional (default=all nodes)
        # A container of nodes. The container will be iterated through once.)

        laborForce0 = gvf.nx.degree(common.g, nbunch=self) + \
            1  # +1 to account for the entrepreneur herself

        # required labor force
        laborForceRequired = int(self.plannedProduction /
                                 common.laborProductivity)

        #???????????????????
        # countUnemployed=0
        # for ag in self.agentList:
        #    if not ag.employed: countUnemployed+=1

        # print "I'm entrepreneur %d laborForce %d and required %d unemployed are %d" %\
        #(self.number, laborForce0, laborForceRequired, countUnemployed)

        # no action
        if laborForce0 == laborForceRequired:
            return

        # hire
        if laborForce0 < laborForceRequired:
            n = laborForceRequired - laborForce0
            tmpList = []
            for ag in self.agentList:
                if ag != self:
                    if ag.agType == "workers" and not ag.employed:
                        tmpList.append(ag)

            if len(tmpList) > 0:
                k = min(n, len(tmpList))
                shuffle(tmpList)
                for i in range(k):
                    hired = tmpList[i]
                    hired.employed = True
                    gvf.colors[hired] = "Aqua"
                    gvf.createEdge(self, hired)
                    # self, here, is the hiring firm

            # count edges (workers) of the firm, after hiring (the values is
            # recorded, but not used directly)
            self.numOfWorkers = gvf.nx.degree(common.g, nbunch=self)
            # nbunch : iterable container, optional (default=all nodes)
            # A container of nodes. The container will be iterated through
            # once.
            print("entrepreneur", self.number,
                  "is applying prod. plan and has", self.numOfWorkers,
                  "edge/s after hiring")

        # fire
        if laborForce0 > laborForceRequired:
            n = laborForce0 - laborForceRequired

            # the list of the employees of the firm
            entrepreneurWorkers = gvf.nx.neighbors(common.g, self)
            # print "entrepreneur", self.number, "could fire",
            # entrepreneurWorkers

            # the list returnes by nx is unstable as order
            entrepreneurWorkers = mySort(entrepreneurWorkers)

            if len(entrepreneurWorkers) > 0:  # has to be, but ...
                shuffle(entrepreneurWorkers)
                for i in range(n):
                    fired = entrepreneurWorkers[i]

                    gvf.colors[fired] = "OrangeRed"
                    fired.employed = False

                    # common.g_edge_labels.pop((self,fired)) no labels in edges
                    common.g.remove_edge(self, fired)

            # count edges (workers) after firing (recorded, but not used
            # directly)
            self.numOfWorkers = gvf.nx.degree(common.g, nbunch=self)
            # nbunch : iterable container, optional (default=all nodes)
            # A container of nodes. The container will be iterated through
            # once.
            print("entrepreneur", self.number,
                  "is applying prod. plan and has", self.numOfWorkers,
                  "edge/s after firing")