当前位置: 首页>>代码示例>>Python>>正文


Python Model.setPresolve方法代码示例

本文整理汇总了Python中pyscipopt.Model.setPresolve方法的典型用法代码示例。如果您正苦于以下问题:Python Model.setPresolve方法的具体用法?Python Model.setPresolve怎么用?Python Model.setPresolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyscipopt.Model的用法示例。


在下文中一共展示了Model.setPresolve方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: model

# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import setPresolve [as 别名]
def model():
    # create solver instance
    s = Model()

    # include separator
    sepa = GMI()
    s.includeSepa(sepa, "python_gmi", "generates gomory mixed integer cuts", priority = 1000, freq = 1)

    # turn off presolve
    s.setPresolve(SCIP_PARAMSETTING.OFF)
    # turn off heuristics
    s.setHeuristics(SCIP_PARAMSETTING.OFF)
    # turn off propagation
    s.setIntParam("propagating/maxrounds", 0)
    s.setIntParam("propagating/maxroundsroot", 0)
    # turn off some cuts
    s.setIntParam("separating/strongcg/freq", -1)
    s.setIntParam("separating/gomory/freq", -1)
    s.setIntParam("separating/aggregation/freq", -1)
    s.setIntParam("separating/mcf/freq", -1)
    s.setIntParam("separating/closecuts/freq", -1)
    s.setIntParam("separating/clique/freq", -1)
    s.setIntParam("separating/zerohalf/freq", -1)

    # only two rounds of cuts
    s.setIntParam("separating/maxroundsroot", 2)

    return s
开发者ID:SCIP-Interfaces,项目名称:PySCIPOpt,代码行数:30,代码来源:test_gomory.py

示例2: test_event

# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import setPresolve [as 别名]
def test_event():
    # create solver instance
    s = Model()
    s.hideOutput()
    s.setPresolve(SCIP_PARAMSETTING.OFF)
    eventhdlr = MyEvent()
    s.includeEventhdlr(eventhdlr, "TestFirstLPevent", "python event handler to catch FIRSTLPEVENT")

    # add some variables
    x = s.addVar("x", obj=1.0)
    y = s.addVar("y", obj=2.0)

    # add some constraint
    s.addCons(x + 2*y >= 5)
    # solve problem
    s.optimize()

    # print solution
    assert round(s.getVal(x)) == 5.0
    assert round(s.getVal(y)) == 0.0

    del s

    assert 'eventinit' in calls
    assert 'eventexit' in calls
    assert 'eventexec' in calls
    assert len(calls) == 3
开发者ID:SCIP-Interfaces,项目名称:PySCIPOpt,代码行数:29,代码来源:test_event.py

示例3: solve

# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import setPresolve [as 别名]
    def solve(self, integer=False):
        '''
        By default we solve a linear version of the column generation.
        If integer is True than we solve the problem of finding the best
        routes to be used without column generation.
        '''
        self.integer = integer
        if self.patterns is None:
            self.genInitialPatterns()

        # Creating master Model:
        master = Model("Master problem")

        # Creating pricer:
        if not integer:
            master.setPresolve(SCIP_PARAMSETTING.OFF)

        # Populating master model.
        # Binary variables z_r indicating whether
        # pattern r is used in the solution:
        z = {}

        for i, _ in enumerate(self.patterns):
            z[i] = master.addVar(vtype="B" if integer else "C",
                                 lb=0.0, ub=1.0, name="z_%d" % i)

        # Set objective:
        master.setObjective(quicksum(self.patCost(p)*z[i] for i, p in enumerate(self.patterns)),
                            "minimize")

        clientCons = [None]*len(self.clientNodes)
        
        for i, c in enumerate(self.clientNodes):
            cons = master.addCons(
            quicksum(self.isClientVisited(c, p)*z[i] for i, p in enumerate(self.patterns)) == 1,
                "Consumer_%d" % c,
                separate=False, modifiable=True)

            clientCons[i] = cons

        if not integer:
            pricer = VRPpricer(z, clientCons, self.data, self.patterns,
                               self.data.costs, self.isClientVisited,
                               self.patCost, self.maxPatterns)

            master.includePricer(pricer, "VRP pricer", "Identifying new routes")

            self.pricer = pricer

        if integer:
            print("Finding the best patterns among:")
            for p in self.patterns:
                print(p)

        self.master = master  # Save master model.
        
        master.optimize()
开发者ID:pedrocastellucci,项目名称:playground,代码行数:59,代码来源:vrp_scip_cg.py

示例4: pricerredcost

# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import setPresolve [as 别名]
    def pricerredcost(self):

        # Retreiving the dual solutions
        dualSolutions = []
        for i, c in enumerate(self.data['cons']):
            dualSolutions.append(self.model.getDualsolLinear(c))

        # Building a MIP to solve the subproblem
        subMIP = Model("CuttingStock-Sub")

        # Turning off presolve
        subMIP.setPresolve(SCIP_PARAMSETTING.OFF)

        # Setting the verbosity level to 0
        subMIP.hideOutput()

        cutWidthVars = []
        varNames = []
        varBaseName = "CutWidth"

        # Variables for the subMIP
        for i in range(len(dualSolutions)):
            varNames.append(varBaseName + "_" + str(i))
            cutWidthVars.append(subMIP.addVar(varNames[i], vtype = "I", obj = -1.0 * dualSolutions[i]))

        # Adding the knapsack constraint
        knapsackCoeffs = {cutWidthVars[i] : self.data['widths'][i] for i in range(len(self.data['widths']))}
        knapsackCons = subMIP.addCons(knapsackCoeffs, lhs = None, rhs = self.data['rollLength'])

        # Solving the subMIP to generate the most negative reduced cost pattern
        subMIP.optimize()

        objval = 1 + subMIP.getObjVal()

        # Adding the column to the master problem
        if objval < -1e-08:
            currentNumVar = len(self.data['var'])

            # Creating new var; must set pricedVar to True
            newVar = self.model.addVar("NewPattern_" + str(currentNumVar), vtype = "C", obj = 1.0, pricedVar = True)

            # Adding the new variable to the constraints of the master problem
            newPattern = []
            for i, c in enumerate(self.data['cons']):
                coeff = round(subMIP.getVal(cutWidthVars[i]))
                self.model.addConsCoeff(c, newVar, coeff)

                newPattern.append(coeff)

            # Storing the new variable in the pricer data.
            self.data['patterns'].append(newPattern)
            self.data['var'].append(newVar)

        # Freeing the subMIP
        subMIP.free()

        return {'result':SCIP_RESULT.SUCCESS}
开发者ID:gorhan,项目名称:LFOS,代码行数:59,代码来源:test_pricer.py

示例5: test_heur

# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import setPresolve [as 别名]
def test_heur():
    # create solver instance
    s = Model()
    heuristic = MyHeur()
    s.includeHeur(heuristic, "PyHeur", "custom heuristic implemented in python", "Y", timingmask=SCIP_HEURTIMING.BEFORENODE)
    s.setPresolve(SCIP_PARAMSETTING.OFF)

    # add some variables
    x = s.addVar("x", obj=1.0)
    y = s.addVar("y", obj=2.0)

    # add some constraint
    s.addCons(x + 2*y >= 5)

    # solve problem
    s.optimize()

    # print solution
    assert round(s.getVal(x)) == 5.0
    assert round(s.getVal(y)) == 0.0
开发者ID:SCIP-Interfaces,项目名称:PySCIPOpt,代码行数:22,代码来源:test_heur.py

示例6: test_cuttingstock

# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import setPresolve [as 别名]
def test_cuttingstock():
    # create solver instance
    s = Model("CuttingStock")

    s.setPresolve(0)

    # creating a pricer
    pricer = CutPricer()
    s.includePricer(pricer, "CuttingStockPricer", "Pricer to identify new cutting stock patterns")

    # item widths
    widths = [14, 31, 36, 45]
    # width demand
    demand = [211, 395, 610, 97]
    # roll length
    rollLength = 100
    assert len(widths) == len(demand)

    # adding the initial variables
    cutPatternVars = []
    varNames = []
    varBaseName = "Pattern"
    patterns = []

    initialCoeffs = []
    for i in range(len(widths)):
        varNames.append(varBaseName + "_" + str(i))
        cutPatternVars.append(s.addVar(varNames[i], obj = 1.0))

    # adding a linear constraint for the knapsack constraint
    demandCons = []
    for i in range(len(widths)):
        numWidthsPerRoll = float(int(rollLength/widths[i]))
        demandCons.append(s.addCons(numWidthsPerRoll*cutPatternVars[i] >= demand[i],
                                    separate = False, modifiable = True))
        newPattern = [0]*len(widths)
        newPattern[i] = numWidthsPerRoll
        patterns.append(newPattern)

    # Setting the pricer_data for use in the init and redcost functions
    pricer.data = {}
    pricer.data['var'] = cutPatternVars
    pricer.data['cons'] = demandCons
    pricer.data['widths'] = widths
    pricer.data['demand'] = demand
    pricer.data['rollLength'] = rollLength
    pricer.data['patterns'] = patterns

    # solve problem
    s.optimize()

    # print original data
    printWidths = '\t'.join(str(e) for e in widths)
    print('\nInput Data')
    print('==========')
    print('Roll Length:', rollLength)
    print('Widths:\t', printWidths)
    print('Demand:\t', '\t'.join(str(e) for e in demand))

    # print solution
    widthOutput = [0]*len(widths)
    print('\nResult')
    print('======')
    print('\t\tSol Value', '\tWidths\t', printWidths)
    for i in range(len(pricer.data['var'])):
        rollUsage = 0
        solValue = round(s.getVal(pricer.data['var'][i]))
        if solValue > 0:
            outline = 'Pattern_' + str(i) + ':\t' + str(solValue) + '\t\tCuts:\t'
            for j in range(len(widths)):
                rollUsage += pricer.data['patterns'][i][j]*widths[j]
                widthOutput[j] += pricer.data['patterns'][i][j]*solValue
                outline += str(pricer.data['patterns'][i][j]) + '\t'
            outline += 'Usage:' + str(rollUsage)
            print(outline)

    print('\t\t\tTotal Output:','\t'.join(str(e) for e in widthOutput))
开发者ID:fserra,项目名称:PySCIPOpt,代码行数:79,代码来源:test_pricer.py

示例7: Copyright

# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import setPresolve [as 别名]
maximize  15x + 18y + 30z
subject to 2x +   y +   z <= 60
           x  +  2y +   z <= 60
                        z <= 30
           x,y,z >= 0
Variables correspond to the production of three types of wine blends,
made from pure-grape wines.
Constraints correspond to the inventory of pure-grape wines.

Copyright (c) by Joao Pedro PEDROSO and Mikio KUBO, 2012
"""
from pyscipopt import Model, quicksum, SCIP_PARAMSETTING

#Initialize model
model = Model("Wine blending")
model.setPresolve(SCIP_PARAMSETTING.OFF)

Inventory = {"Alfrocheiro":60, "Baga":60, "Castelao":30}
Grapes = Inventory.keys()

Profit = {"Dry":15, "Medium":18, "Sweet":30}
Blends = Profit.keys()

Use = {
    ("Alfrocheiro","Dry"):2,
    ("Alfrocheiro","Medium"):1,
    ("Alfrocheiro","Sweet"):1,
    ("Baga","Dry"):1,
    ("Baga","Medium"):2,
    ("Baga","Sweet"):1,
    ("Castelao","Dry"):0,
开发者ID:SCIP-Interfaces,项目名称:PySCIPOpt,代码行数:33,代码来源:lo_wines.py

示例8: getColumnFromMIP

# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import setPresolve [as 别名]
    def getColumnFromMIP(self, timeLimit):

        def getPatternFromSolution(subMIP):
            edges = []
            for x in subMIP.getVars():
                if "x" in x.name:
                    if subMIP.getVal(x) > 0.99:
                        i, j = x.name.split("_")[1:]
                        edges.append((int(i), int(j)))
                    
            return edges

        # Storing the values of the dual solutions:
        dualSols = {}
        for c in self.cons:
            i = int(c.name.split("_")[-1].strip())
            dualSols[i] = self.model.getDualsolLinear(c)

        # Model for the sub-problem:
        subMIP = Model("VRP-Sub")
        subMIP.setPresolve(SCIP_PARAMSETTING.OFF)
        subMIP.setMinimize

        subMIP.setRealParam("limits/time", timeLimit)
        
        # Binary variables x_ij indicating whether the vehicle
        # traverses edge (i, j)
        x = {}
        for i in self.data.nodes:
            for j in self.data.nodes:
                if i != j:
                    x[i, j] = subMIP.addVar(vtype="B", obj=self.data.costs[i, j] - (dualSols[i] if i in self.clientNodes else 0), name="x_%d_%d" % (i, j))

        # Non negative variables u_i indicating the demand served up to node i:
        u = {}
        for i in self.data.nodes:
            u[i] = subMIP.addVar(vtype="C", lb=0, ub=self.data.cap, obj=0.0, name="u_%d" % i)

        for j in self.clientNodes:
            subMIP.addCons(quicksum(x[i, j] for i in self.data.nodes if i != j) <= 1)

        for h in self.clientNodes:
            subMIP.addCons(quicksum(x[i, h] for i in self.data.nodes if i != h) ==
                           quicksum(x[h, i] for i in self.data.nodes if i != h))

        for i in self.data.nodes:
            for j in self.clientNodes:
                if i != j:
                    subMIP.addCons(u[j] >= u[i] + self.data.demands[j]*x[i, j] - self.data.cap*(1 - x[i, j]))

        subMIP.addCons(quicksum(x[self.data.depot, j] for j in self.clientNodes) <= 1)

        subMIP.hideOutput()
        subMIP.optimize()

        mipSol = subMIP.getBestSol()
        obj = subMIP.getSolObjVal(mipSol)
        
        pattern = getPatternFromSolution(subMIP)
        
        return obj, pattern
开发者ID:pedrocastellucci,项目名称:playground,代码行数:63,代码来源:vrp_scip_cg.py


注:本文中的pyscipopt.Model.setPresolve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。