# Solving equations with iterations

**URL:** <https://discuss.ampl.com/t/solving-equations-with-iterations/663>\
**Category:** Support\
**Created:** [July 31, 2023, 4:18am UTC](https://discuss.ampl.com/t/solving-equations-with-iterations/663 "2023-07-31T04:18:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajender\_Mudigonda](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/rajender_mudigonda/32/360_2.png) [@Rajender\_Mudigonda](https://discuss.ampl.com/u/Rajender_Mudigonda)\
**Post date:** [July 31, 2023, 4:18am UTC](https://discuss.ampl.com/t/solving-equations-with-iterations/663/1 "2023-07-31T04:18:27Z")

</div>

Hi All,  
I have to optimize a set of equations that have cyclic iterations. I have a pyomo code as below. I tried with a couple of solvers, but all of them hang. Is there a way to handle cycles?

Thanks and Regards

from pyomo.environ import \*

from vmplib import \*

import sys

import traceback

#sys.setrecursionlimit(90000)

model = ConcreteModel()

model.limits = ConstraintList()

#Taxpayer v0.2\>Taxpayer v0.2 Plan Criterion Set\>Start cash\>Start cash Value MeasurementMC

model.x8 = Var(within=NonNegativeReals,initialize=1000.0000)

#Taxpayer v0.2\>Taxpayer v0.2 Plan Criterion Set\>Cash\>Cash Value MeasurementMC

model.x4 = Objective()

model.x4.set\_sense(maximize)

#Cash model Package\>Employment network\>Employer\>Net salary\>Net salary amount\>Net salary amount Value MeasurementMC

model.x7 = Var(within=NonNegativeReals,initialize=25000.0000)

#Cash model Package\>Cash network\>Banker\>Savings account\>Interest rate\>Interest rate Value MeasurementMC

model.x5 = Var(within=NonNegativeReals,initialize=5.0000)

#Cash model Package\>Cash network\>Taxpayer\>Tax\>Tax rate\>Tax rate Value MeasurementMC

model.x3 = Var(within=NonNegativeReals,initialize=50.0000)

#Cash model Package\>Cash network\>Saver\>Revenue streams\>Net income from labor\>Net income from labor Value MeasurementMC

model.x6 = Expression()

#Cash model Package\>Cash network\>Saver\>Revenue streams\>Income from interest\>Income from interest Value MeasurementMC

model.x2 = Expression()

#Cash model Package\>Cash network\>Saver\>Cost structures\>Tax payment\>Tax payment Value MeasurementMC

model.x1 = Expression()

#Taxpayer v0.2\>Taxpayer v0.2 Plan Criterion Set\>Cash\>Cash Value MeasurementMC

model.x4.set\_value(model.x8+model.x6+ model.x2-model.x1)

model.c4 = Constraint(expr=model.x4 \>= 0)

#Cash model Package\>Cash network\>Saver\>Revenue streams\>Net income from labor\>Net income from labor Value MeasurementMC

model.x6.set\_value(model.x7)

model.c6 = Constraint(expr=model.x6 \>= 0)

#Cash model Package\>Cash network\>Saver\>Revenue streams\>Income from interest\>Income from interest Value MeasurementMC

model.x2.set\_value(model.x4-0.01\*model.x5)

model.c2 = Constraint(expr=model.x2 \>= 0)

#Cash model Package\>Cash network\>Saver\>Cost structures\>Tax payment\>Tax payment Value MeasurementMC

model.x1.set\_value(model.x2 - 0.01\*model.x3)

model.c1 = Constraint(expr=model.x1 \>= 0)

def maxz(m):

return m.x4 \<= 26666.6666

model.constz = Constraint(rule = maxz)

solver = SolverFactory(‘couenne’)

solver.options[‘max\_iter’] = 6000

try:

results = solver.solve(model, tee=True)

except:

traceback.print\_exc()

response = {‘error’: ‘error handling request’}

traceback.print\_exc()

---

<div class="post-metadata">

**Author:** ![4er](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/4er/32/530_2.png) [@4er](https://discuss.ampl.com/u/4er)\
**Post date:** [August 1, 2023, 5:23pm UTC](https://discuss.ampl.com/t/solving-equations-with-iterations/663/2 "2023-08-01T17:23:23Z")

</div>

Dear Rajender,

This forum provides advice for using the AMPL modeling language and system. To get help with Pyomo, post a question on the Pyomo Forum at [https://groups.google.com/g/pyomo-forum](https://groups.google.com/g/pyomo-forum).
