當前位置: 首頁>>代碼示例>>Python>>正文


Python CyClpSimplex.readMps方法代碼示例

本文整理匯總了Python中cylp.cy.CyClpSimplex.readMps方法的典型用法代碼示例。如果您正苦於以下問題:Python CyClpSimplex.readMps方法的具體用法?Python CyClpSimplex.readMps怎麽用?Python CyClpSimplex.readMps使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cylp.cy.CyClpSimplex的用法示例。


在下文中一共展示了CyClpSimplex.readMps方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: solve

# 需要導入模塊: from cylp.cy import CyClpSimplex [as 別名]
# 或者: from cylp.cy.CyClpSimplex import readMps [as 別名]
def solve(filename, method):

    s = CyClpSimplex()
    s.readMps(filename)

    s.preSolve(feasibilityTolerance=10 ** -8)
    #s.useCustomPrimal(1)

    if method == 'd':
        pivot = DantzigPivot(s)
    elif method == 'l':
        pivot = LIFOPivot(s)
    elif method == 'm':
        pivot = MostFrequentPivot(s)
    elif method == 'p':
        pivot = PositiveEdgePivot(s)
    else:
        print 'Unkown solution method.'
        sys.exit(1)

    s.setPivotMethod(pivot)

    #s.setPerturbation(50)

    start = clock()
    s.primal()
    print 'Problem solved in %g seconds.' % (clock() - start)
    return s.objectiveValue
開發者ID:HerrKevin,項目名稱:CyLP,代碼行數:30,代碼來源:PySolve.py

示例2: test_1

# 需要導入模塊: from cylp.cy import CyClpSimplex [as 別名]
# 或者: from cylp.cy.CyClpSimplex import readMps [as 別名]
    def test_1(self):
        """simplest QP test"""
        s = CyClpSimplex()
        s.readMps(join(currentFilePath, '../input/hs35.qps'))
        #self.assertTrue(abs(cbcModel.objectiveValue - 3089.0) < 10 ** -6)
        
        #print s.Hessian.todense()

        p = WolfePivot(s)
        s.setPivotMethod(p)

        s.primal()
        print s.primalVariableSolution
        print s.objectiveValue
開發者ID:HerrKevin,項目名稱:CyLP,代碼行數:16,代碼來源:test_QP.py

示例3: TestCyClpSimplex

# 需要導入模塊: from cylp.cy import CyClpSimplex [as 別名]
# 或者: from cylp.cy.CyClpSimplex import readMps [as 別名]
class TestCyClpSimplex(unittest.TestCase):

    def setUp(self):
        self.s = CyClpSimplex()
        self.s.readMps(join(currentFilePath, '../input/p0033.mps'))

    def test_PE(self):
        #pivot = PositiveEdgePivot(self.s)
        self.s.setPivotMethod(PositiveEdgePivot(self.s))
        self.s.primal()
        self.assertEqual(round(self.s.objectiveValue, 4), 2520.5717)

    def test_Dantzig(self):
        #pivot = DantzigPivot(self.s)
        self.s.setPivotMethod(DantzigPivot(self.s))
        self.s.primal()
        self.assertEqual(round(self.s.objectiveValue, 4), 2520.5717)

    def test_LIFO(self):
        #pivot = LIFOPivot(self.s)
        self.s.setPivotMethod(LIFOPivot(self.s))
        self.s.primal()
        self.assertEqual(round(self.s.objectiveValue, 4), 2520.5717)

    def test_MostFrequent(self):
        #pivot = MostFrequentPivot(self.s)
        self.s.setPivotMethod(MostFrequentPivot(self.s))
        self.s.primal()
        self.assertEqual(round(self.s.objectiveValue, 4), 2520.5717)

    def test_initialSolve(self):
        self.s.initialSolve()
        self.assertEqual(round(self.s.objectiveValue, 4), 2520.5717)

    def test_initialPrimalSolve(self):
        self.s.initialPrimalSolve()
        self.assertEqual(round(self.s.objectiveValue, 4), 2520.5717)

    def test_initialDualSolve(self):
        self.s.initialDualSolve()
        self.assertEqual(round(self.s.objectiveValue, 4), 2520.5717)

    def test_direction(self):
        self.assertEqual(self.s.optimizationDirection, 'min')
        self.s.optimizationDirection = 'max'
        self.assertEqual(self.s.optimizationDirection, 'max')
開發者ID:HerrKevin,項目名稱:CyLP,代碼行數:48,代碼來源:test_CyClpSimplex.py

示例4: test_NodeCompare

# 需要導入模塊: from cylp.cy import CyClpSimplex [as 別名]
# 或者: from cylp.cy.CyClpSimplex import readMps [as 別名]
    def test_NodeCompare(self):
        s = CyClpSimplex()
        s.readMps(join(currentFilePath, '../input/p0033.mps'))

        s.copyInIntegerInformation(np.array(s.nCols * [True], np.uint8))

        print "Solving relaxation"
        cbcModel = s.getCbcModel()
        n = SimpleNodeCompare()
        cbcModel.setNodeCompare(n)

        gom = CyCglGomory(limit=150)
        #gom.limit = 150
        cbcModel.addCutGenerator(gom, name="Gomory")

        #clq = CyCglClique()
        #cbcModel.addCutGenerator(clq, name="Clique")

        knap = CyCglKnapsackCover(maxInKnapsack=50)
        cbcModel.addCutGenerator(knap, name="Knapsack")


        cbcModel.branchAndBound()
        self.assertTrue(abs(cbcModel.objectiveValue - 3089.0) < 10 ** -6)
開發者ID:HerrKevin,項目名稱:CyLP,代碼行數:26,代碼來源:test_MIP.py

示例5: saveWeights

# 需要導入模塊: from cylp.cy import CyClpSimplex [as 別名]
# 或者: from cylp.cy.CyClpSimplex import readMps [as 別名]
            #del rc2
            return  indicesToConsider[ind]
        return -1

    def saveWeights(self, model, mode):
        self.clpModel = model

    def isPivotAcceptable(self):
        return True


def getMpsExample():
    import os
    import inspect
    cylpDir = os.environ['CYLP_SOURCE_DIR']
    return os.path.join(cylpDir, 'cylp', 'input', 'p0033.mps')


if __name__ == "__main__":
    if len(sys.argv) == 1:
        import doctest
        doctest.testmod()
    else:
        from cylp.cy import CyClpSimplex
        from cylp.py.pivots import DantzigPivot
        s = CyClpSimplex()
        s.readMps(sys.argv[1])
        pivot = DantzigPivot(s)
        s.setPivotMethod(pivot)
        s.primal()
開發者ID:HerrKevin,項目名稱:CyLP,代碼行數:32,代碼來源:DantzigPivot.py

示例6: getMpsExample

# 需要導入模塊: from cylp.cy import CyClpSimplex [as 別名]
# 或者: from cylp.cy.CyClpSimplex import readMps [as 別名]
            model.solution[basicVarInds[rowNumbers]] -= change

        changeObj = -np.dot(change, cost)
        primalUpdate.clear()
        objectiveChange[0] += changeObj

        return changeObj


def getMpsExample():
    import os
    import inspect
    import sys
    cylpDir = os.environ['CYLP_SOURCE_DIR']
    return os.path.join(cylpDir, 'cylp', 'input', 'p0033.mps')


if __name__ == "__main__":
    print sys.argv
    if len(sys.argv) == 1:
        import doctest
        doctest.testmod()
    else:
        from cylp.cy import CyClpSimplex
        from cylp.py.pivots import DualDantzigPivot
        s = CyClpSimplex()
        s.readMps(sys.argv[1])  # Returns 0 if OK
        pivot = DualDantzigPivot(s)
        s.setDualPivotMethod(pivot)
        s.dual()
開發者ID:HerrKevin,項目名稱:CyLP,代碼行數:32,代碼來源:DualDantzigPivot.py


注:本文中的cylp.cy.CyClpSimplex.readMps方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。