Пример #1
0
 def printTotMats(self):
     """print the total mats required for the optimized items"""
     print "ITEMS INVENTABLE WITH CURRENT RESOURCES:"
     for i in self.itemList:
         idx = self.blueprints.blueprints[StaticData.originatorBp(
             i)].T2.inventedIDs.index(i)
         print "{}\t{}".format(
             StaticData.idName(i), self.blueprints.blueprints[
                 StaticData.originatorBp(i)].t2Priority[idx][1])
Пример #2
0
    def requiredBaseMaterials(self, typeID):
        """return the total base materials needed for a given item"""
        components = self.requiredComponents(typeID)
        breakDownDict = {}
        for component in components:
            bpTypeID = StaticData.producerID(component)
            if bpTypeID:  #this stupid conditional is needed because producerID returns strings but i need int, but if producerID returns null int throws an error.
                bpTypeID = int(bpTypeID)
            if not bpTypeID:
                breakDownDict[component] = components[component]
                continue
            elif bpTypeID in self.blueprints.blueprints:
                if self.blueprints.blueprints[bpTypeID].BPO.component == 1:
                    mats = self._componentsMaterialsCalculator(
                        components[component],
                        self.blueprints.blueprints[bpTypeID].BPO)
                    breakDownDict[component] = mats
                elif self.blueprints.blueprints[bpTypeID].BPO.component == 0:
                    mats = self.t1MaterialCost(
                        components[component],
                        self.blueprints.blueprints[bpTypeID])
                    breakDownDict[component] = mats

        try:
            return MatsBreakDown(breakDownDict, typeID,
                                 self.blueprints.blueprints[typeID].manufSize,
                                 components)
        except KeyError:
            t1TypeID = StaticData.originatorBp(typeID)
            return MatsBreakDown(
                breakDownDict, typeID,
                self.blueprints.blueprints[t1TypeID].manufSize, components)
Пример #3
0
    def T2Inventables(self):
        """determine inventable T2 items"""
        #vars
        items = []  #list of all blueprints
        objectiveFunction = {
        }  #names of items, this is the objective function "name": required invention runs
        datacoresDict = {
        }  #a dict containing another dict for every resource. the latter contains the amount of that resource required for every object

        #determine total resources
        for blueprintID in self.blueprints.blueprints:
            bpContainer = self.blueprints.blueprints[blueprintID]
            if not bpContainer.T2.inventable:
                continue
            for idx in range(len(bpContainer.T2.inventedIDs)):
                if not bpContainer.t2Priority[idx][0] == 'invention':
                    continue

                reqDatacores = StaticData.datacoreRequirements(
                    StaticData.originatorBp(bpContainer.T2.inventedIDs[idx]))
                items.append(bpContainer.T2.inventedIDs[idx])
                objectiveFunction[bpContainer.T2.inventedIDs[idx]] = 1
                for datacore in reqDatacores:
                    if datacore not in datacoresDict:
                        datacoresDict[datacore] = {}

        for blueprintID in self.blueprints.blueprints:
            bpContainer = self.blueprints.blueprints[blueprintID]
            if not bpContainer.T2.inventable:
                continue
            for idx in range(len(bpContainer.T2.inventedIDs)):
                bpTypeID = bpContainer.T2.inventedIDs[idx]
                if not bpContainer.t2Priority[idx][0] == 'invention':
                    continue
                reqDatacores = StaticData.datacoreRequirements(
                    StaticData.originatorBp(bpTypeID))

                for datacore in datacoresDict:
                    if datacore in reqDatacores:
                        datacoresDict[datacore][bpTypeID] = reqDatacores[
                            datacore] * bpContainer.t2Priority[idx][1]
                    else:
                        datacoresDict[datacore][bpTypeID] = 0

        prob = LpProblem("t2 inventable items", LpMaximize)
        itemVars = LpVariable.dicts("items", items, 0, 1, LpInteger)

        prob += lpSum([objectiveFunction[i] * itemVars[i] for i in items
                       ]), "all items, this represents the objective function"

        for datacore in datacoresDict:
            if datacore in self.materials:
                ownedMat = self.materials[datacore]
            else:
                ownedMat = 0
            prob += lpSum(
                [datacoresDict[datacore][x] * itemVars[x]
                 for x in items]) <= ownedMat, StaticData.idName(datacore)

        prob.solve()

        #for v in prob.variables():
        #  print(v.name, "=", v.varValue)

        return DatacoreOptimizedAggregator(prob.variables(), self.blueprints,
                                           self.materials)
Пример #4
0
    def requiredComponents(self, typeID):
        """return the component materials needed for an item"""
        typeID = int(typeID)
        if typeID in self.blueprints.blueprints and self.blueprints.blueprints[
                typeID].t1Priority[0] == 'manufacture':
            blueprint = self.blueprints.blueprints[typeID]
            manufSize = blueprint.manufSize
            totalMaterialCost = self.t1MaterialCost(manufSize, blueprint)
            return totalMaterialCost
        elif StaticData.originatorBp(typeID) in self.blueprints.blueprints:
            blueprint = self.blueprints.blueprints[StaticData.originatorBp(
                typeID)]
            inventedIndex = ''
            for idx, i in enumerate(blueprint.T2.inventedIDs):
                if typeID == i:
                    inventedIndex = int(idx)
            if blueprint.t2Priority[inventedIndex][0] == 'manufacture':
                totalMaterialCost = {}
                manufSize = blueprint.manufSize

                #logic that decides which bpc to use given the amount of things to produce
                sortedBPCs = sorted(blueprint.T2.items[inventedIndex],
                                    key=lambda x: x.TE)

                for BPC in sortedBPCs:
                    if manufSize - BPC.runs > 0:
                        modMaterialCost = self._BPCmaterialsCalculator(
                            BPC.runs, BPC)
                        for matID in modMaterialCost:
                            if matID in totalMaterialCost:
                                totalMaterialCost[matID] += modMaterialCost[
                                    matID]
                            else:
                                totalMaterialCost[matID] = modMaterialCost[
                                    matID]
                        manufSize = manufSize - BPC.runs
                    elif manufSize - BPC.runs == 0:
                        modMaterialCost = self._BPCmaterialsCalculator(
                            BPC.runs, BPC)
                        for matID in modMaterialCost:
                            if matID in totalMaterialCost:
                                totalMaterialCost[matID] += modMaterialCost[
                                    matID]
                            else:
                                totalMaterialCost[matID] = modMaterialCost[
                                    matID]
                        break
                    elif manufSize - BPC.runs < 0:
                        modMaterialCost = self._BPCmaterialsCalculator(
                            manufSize, BPC)
                        for matID in modMaterialCost:
                            if matID in totalMaterialCost:
                                totalMaterialCost[matID] += modMaterialCost[
                                    matID]
                            else:
                                totalMaterialCost[matID] = modMaterialCost[
                                    matID]
                        break
                return totalMaterialCost
            else:
                raise TypeError("wrong. {}".format(StaticData.idName(typeID)))