本文整理汇总了Python中cylp.cy.CyClpSimplex.initialSolve方法的典型用法代码示例。如果您正苦于以下问题:Python CyClpSimplex.initialSolve方法的具体用法?Python CyClpSimplex.initialSolve怎么用?Python CyClpSimplex.initialSolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cylp.cy.CyClpSimplex
的用法示例。
在下文中一共展示了CyClpSimplex.initialSolve方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCyClpSimplex
# 需要导入模块: from cylp.cy import CyClpSimplex [as 别名]
# 或者: from cylp.cy.CyClpSimplex import initialSolve [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')
示例2: Single_Year_Stage_II
# 需要导入模块: from cylp.cy import CyClpSimplex [as 别名]
# 或者: from cylp.cy.CyClpSimplex import initialSolve [as 别名]
#.........这里部分代码省略.........
print("Preparing targets for ", year)
APOPN = Stage_I_factors[year]["APOPN"]
b = []
b.append(Stage_II_targets[year]['Single']-single_return.sum())
b.append(Stage_II_targets[year]['Joint']-joint_return.sum())
b.append(Stage_II_targets[year]['HH']-hh_return.sum())
b.append(Stage_II_targets[year]['SS_return']-return_w_SS.sum())
b.append(Stage_II_targets[year]['Dep_return'] - dependent_exempt_num.sum())
AINTS = Stage_I_factors[year]["AINTS"]
INTEREST = Stage_II_targets[year]['INTS']*APOPN/AINTS*1000-interest.sum()
ADIVS = Stage_I_factors[year]["ADIVS"]
DIVIDEND = Stage_II_targets[year]['DIVS']*APOPN/ADIVS*1000 - dividend.sum()
ASCHCI = Stage_I_factors[year]["ASCHCI"]
BIZ_INCOME = Stage_II_targets[year]['SCHCI']*APOPN/ASCHCI*1000 - biz_income.sum()
ASCHCL = Stage_I_factors[year]["ASCHCL"]
BIZ_LOSS = Stage_II_targets[year]['SCHCL']*APOPN/ASCHCL*1000 - biz_loss.sum()
ACGNS = Stage_I_factors[year]["ACGNS"]
CAP_GAIN = Stage_II_targets[year]['CGNS']*APOPN/ACGNS*1000 - cap_gain.sum()
ATXPY = Stage_I_factors[year]["ATXPY"]
ANNUITY_PENSION = Stage_II_targets[year]['Pension']*APOPN/ATXPY*1000 - annuity_pension.sum()
ASCHEI = Stage_I_factors[year]["ASCHEI"]
SCH_E_INCOME = Stage_II_targets[year]["SCHEI"]*APOPN/ASCHEI*1000 - sch_e_income.sum()
ASCHEL = Stage_I_factors[year]["ASCHEL"]
SCH_E_LOSS = Stage_II_targets[year]["SCHEL"]*APOPN/ASCHEL*1000 - sch_e_loss.sum()
ASOCSEC = Stage_I_factors[year]["ASOCSEC"]
APOPSNR = Stage_I_factors[year]["APOPSNR"]
SS_INCOME = Stage_II_targets[year]["SS"]*APOPSNR/ASOCSEC*1000 - ss_income.sum()
AUCOMP = Stage_I_factors[year]["AUCOMP"]
UNEMPLOYMENT_COMP = Stage_II_targets[year]["UCOMP"]*APOPN/AUCOMP*1000 - unemployment_comp.sum()
AWAGE = Stage_I_factors[year]["AWAGE"]
WAGE_1 = Stage_II_targets[year]["WAGE_1"]*APOPN/AWAGE*1000 - wage_1.sum()
WAGE_2 = Stage_II_targets[year]["WAGE_2"]*APOPN/AWAGE*1000 - wage_2.sum()
WAGE_3 = Stage_II_targets[year]["WAGE_3"]*APOPN/AWAGE*1000 - wage_3.sum()
WAGE_4 = Stage_II_targets[year]["WAGE_4"]*APOPN/AWAGE*1000 - wage_4.sum()
WAGE_5 = Stage_II_targets[year]["WAGE_5"]*APOPN/AWAGE*1000 - wage_5.sum()
WAGE_6 = Stage_II_targets[year]["WAGE_6"]*APOPN/AWAGE*1000 - wage_6.sum()
WAGE_7 = Stage_II_targets[year]["WAGE_7"]*APOPN/AWAGE*1000 - wage_7.sum()
WAGE_8 = Stage_II_targets[year]["WAGE_8"]*APOPN/AWAGE*1000 - wage_8.sum()
WAGE_9 = Stage_II_targets[year]["WAGE_9"]*APOPN/AWAGE*1000 - wage_9.sum()
WAGE_10 = Stage_II_targets[year]["WAGE_10"]*APOPN/AWAGE*1000 - wage_10.sum()
WAGE_11 = Stage_II_targets[year]["WAGE_11"]*APOPN/AWAGE*1000 - wage_11.sum()
WAGE_12 = Stage_II_targets[year]["WAGE_12"]*APOPN/AWAGE*1000 - wage_12.sum()
temp = [INTEREST,DIVIDEND, BIZ_INCOME, BIZ_LOSS, CAP_GAIN, ANNUITY_PENSION, SCH_E_INCOME, SCH_E_LOSS, SS_INCOME, UNEMPLOYMENT_COMP,
WAGE_1,WAGE_2, WAGE_3,WAGE_4, WAGE_5, WAGE_6, WAGE_7,WAGE_8,WAGE_9, WAGE_10, WAGE_11, WAGE_12]
for m in temp:
b.append(m)
targets = CyLPArray(b)
print("Targets for year ", year, " is ", targets)
LP = CyLPModel()
r = LP.addVariable('r', length)
s = LP.addVariable('s', length)
print("Adding constraints")
LP.addConstraint(r >=0, "positive r")
LP.addConstraint(s >=0, "positive s")
LP.addConstraint(r + s <= tol, "abs upperbound")
c = CyLPArray((np.ones(length)))
LP.objective = c * r + c * s
LP.addConstraint(A1 * r + A2 * s == targets, "Aggregates")
print("Setting up the LP model")
model = CyClpSimplex(LP)
print("Solving LP......")
model.initialSolve()
print("DONE!!")
z = np.empty([length])
z = (1+model.primalVariableSolution['r'] - model.primalVariableSolution['s'])*s006
return z
示例3: Single_Year_Stage_II
# 需要导入模块: from cylp.cy import CyClpSimplex [as 别名]
# 或者: from cylp.cy.CyClpSimplex import initialSolve [as 别名]
#.........这里部分代码省略.........
print("Preparing targets for ", year)
APOPN = Stage_I_factors[year]["APOPN"]
b = []
b.append(Stage_II_targets[year]['Single Returns']-single_return.sum())
b.append(Stage_II_targets[year]['Joint Returns']-joint_return.sum())
b.append(Stage_II_targets[year]['Head of Household Returns']-hh_return.sum())
b.append(Stage_II_targets[year]['Number of Returns w/ Gross Security Income']-return_w_SS.sum())
b.append(Stage_II_targets[year]['Number of Dependent Exemptions'] - dependent_exempt_num.sum())
AINTS = Stage_I_factors[year]["AINTS"]
INTEREST = Stage_II_targets[year]['Taxable Interest Income']*APOPN/AINTS*1000-interest.sum()
ADIVS = Stage_I_factors[year]["ADIVS"]
DIVIDEND = Stage_II_targets[year]['Ordinary Dividends']*APOPN/ADIVS*1000 - dividend.sum()
ASCHCI = Stage_I_factors[year]["ASCHCI"]
BIZ_INCOME = Stage_II_targets[year]['Business Income (Schedule C)']*APOPN/ASCHCI*1000 - biz_income.sum()
ASCHCL = Stage_I_factors[year]["ASCHCL"]
BIZ_LOSS = Stage_II_targets[year]['Business Loss (Schedule C)']*APOPN/ASCHCL*1000 - biz_loss.sum()
ACGNS = Stage_I_factors[year]["ACGNS"]
CAP_GAIN = Stage_II_targets[year]['Net Capital Gains in AGI']*APOPN/ACGNS*1000 - cap_gain.sum()
ATXPY = Stage_I_factors[year]["ATXPY"]
ANNUITY_PENSION = Stage_II_targets[year]['Taxable Pensions and Annuities']*APOPN/ATXPY*1000 - annuity_pension.sum()
ASCHEI = Stage_I_factors[year]["ASCHEI"]
SCH_E_INCOME = Stage_II_targets[year]["Supplemental Income (Schedule E)"]*APOPN/ASCHEI*1000 - sch_e_income.sum()
ASCHEL = Stage_I_factors[year]["ASCHEL"]
SCH_E_LOSS = Stage_II_targets[year]["Supplemental Loss (Schedule E)"]*APOPN/ASCHEL*1000 - sch_e_loss.sum()
ASOCSEC = Stage_I_factors[year]["ASOCSEC"]
APOPSNR = Stage_I_factors[year]["APOPSNR"]
SS_INCOME = Stage_II_targets[year]["Gross Social Security Income"]*APOPSNR/ASOCSEC*1000 - ss_income.sum()
AUCOMP = Stage_I_factors[year]["AUCOMP"]
UNEMPLOYMENT_COMP = Stage_II_targets[year]["Unemployment Compensation"]*APOPN/AUCOMP*1000 - unemployment_comp.sum()
AWAGE = Stage_I_factors[year]["AWAGE"]
WAGE_1 = Stage_II_targets[year]["Wages and Salaries: Zero or Less"]*APOPN/AWAGE*1000 - wage_1.sum()
WAGE_2 = Stage_II_targets[year]["Wages and Salaries: $1 Less Than $10,000"]*APOPN/AWAGE*1000 - wage_2.sum()
WAGE_3 = Stage_II_targets[year]["Wages and Salaries: $10,000 Less Than $20,000"]*APOPN/AWAGE*1000 - wage_3.sum()
WAGE_4 = Stage_II_targets[year]["Wages and Salaries: $20,000 Less Than $30,000"]*APOPN/AWAGE*1000 - wage_4.sum()
WAGE_5 = Stage_II_targets[year]["Wages and Salaries: $30,000 Less Than $40,000"]*APOPN/AWAGE*1000 - wage_5.sum()
WAGE_6 = Stage_II_targets[year]["Wages and Salaries: $40,000 Less Than $50,000"]*APOPN/AWAGE*1000 - wage_6.sum()
WAGE_7 = Stage_II_targets[year]["Wages and Salaries: $50,000 Less Than $75,000"]*APOPN/AWAGE*1000 - wage_7.sum()
WAGE_8 = Stage_II_targets[year]["Wages and Salaries: $75,000 Less Than $100,000"]*APOPN/AWAGE*1000 - wage_8.sum()
WAGE_9 = Stage_II_targets[year]["Wages and Salaries: $100,000 Less Than $200,000"]*APOPN/AWAGE*1000 - wage_9.sum()
WAGE_10 = Stage_II_targets[year]["Wages and Salaries: $200,000 Less Than $500,000"]*APOPN/AWAGE*1000 - wage_10.sum()
WAGE_11 = Stage_II_targets[year]["Wages and Salaries: $500,000 Less Than $1 Million"]*APOPN/AWAGE*1000 - wage_11.sum()
WAGE_12 = Stage_II_targets[year]["Wages and Salaries: $1 Million and Over"]*APOPN/AWAGE*1000 - wage_12.sum()
temp = [INTEREST,DIVIDEND, BIZ_INCOME, BIZ_LOSS, CAP_GAIN, ANNUITY_PENSION, SCH_E_INCOME, SCH_E_LOSS, SS_INCOME, UNEMPLOYMENT_COMP,
WAGE_1,WAGE_2, WAGE_3,WAGE_4, WAGE_5, WAGE_6, WAGE_7,WAGE_8,WAGE_9, WAGE_10, WAGE_11, WAGE_12]
for m in temp:
b.append(m)
targets = CyLPArray(b)
print("Targets for year ", year, " is ", targets)
LP = CyLPModel()
r = LP.addVariable('r', length)
s = LP.addVariable('s', length)
print("Adding constraints")
LP.addConstraint(r >=0, "positive r")
LP.addConstraint(s >=0, "positive s")
LP.addConstraint(r + s <= tol, "abs upperbound")
c = CyLPArray((np.ones(length)))
LP.objective = c * r + c * s
LP.addConstraint(A1 * r + A2 * s == targets, "Aggregates")
print("Setting up the LP model")
model = CyClpSimplex(LP)
print("Solving LP......")
model.initialSolve()
print("DONE!!")
z = np.empty([length])
z = (1+model.primalVariableSolution['r'] - model.primalVariableSolution['s'])*s006 * 100
return z