title: Solving MINLP with PYOMO/PYSP
body: <p>team,</p>
  
  <p>currently I am working on a nonlinear stochastic optimization problem. So far, the toolbox has been really helpful, thank you! However, adding a nonlinear constraint has caused an error. I use the gurobi solver. The problem results from the following constraint.</p>
  
  <pre><code>def max_pcr_power_rule(model, t):
      if t == 0:
          return 0 &lt;= battery.P_bat_max-model.P_sc_max[t+1]-model.P_pcr
      else:       
          return model.P_trade_c[t+1] + np.sqrt(-2*np.log(rob_opt.max_vio)) \
          *sum(model.U_max_pow[t,i]**2 for i in set_sim.tme_dat_stp)**(0.5) \
          &lt;= battery.P_bat_max-model.P_sc_max[t+1]-model.P_pcr
  model.max_pcr_power = Constraint(set_sim.tme_dat_stp, rule=max_pcr_power_rule)
  </code></pre>
  
  <p>I receive this error message:</p>
  
  <blockquote>
    <p>Initializing extensive form algorithm for stochastic programming
    problems. Exception encountered. Scenario tree manager attempting to
    shut down. Traceback (most recent call last):   File
    "C:\Users\theil\Anaconda3\Scripts\runef-script.py", line 5, in
    
        sys.exit(pyomo.pysp.ef_writer_script.main())   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\pysp\ef_writer_script.py",
    line 863, in main
        traceback=options.traceback)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\pysp\util\misc.py",
    line 344, in launch_command
        rc = command(options, *cmd_args, **cmd_kwds)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\pysp\ef_writer_script.py",
    line 748, in runef
        ef.solve()   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\pysp\ef_writer_script.py",
    line 430, in solve
        **solve_kwds)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\opt\parallel\manager.py",
    line 122, in queue
        return self._perform_queue(ah, *args, **kwds)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\opt\parallel\local.py",
    line 59, in _perform_queue
        results = opt.solve(*args, **kwds)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\opt\base\solvers.py",
    line 599, in solve
        self._presolve(*args, **kwds)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\solvers\plugins\solvers\GUROBI.py",
    line 224, in _presolve
        ILMLicensedSystemCallSolver._presolve(self, *args, **kwds)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\opt\solver\shellcmd.py",
    line 196, in _presolve
        OptSolver._presolve(self, *args, **kwds)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\opt\base\solvers.py",
    line 696, in _presolve
        **kwds)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\opt\base\solvers.py",
    line 767, in _convert_problem
        **kwds)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\opt\base\convert.py",
    line 110, in convert_problem
        problem_files, symbol_map = converter.apply(*tmp, **tmpkw)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\solvers\plugins\converter\model.py",
    line 96, in apply
        io_options=io_options)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\core\base\block.py",
    line 1681, in write
        io_options)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\repn\plugins\cpxlp.py",
    line 176, in <strong>call</strong>
        include_all_variable_bounds=include_all_variable_bounds)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\repn\plugins\cpxlp.py",
    line 719, in _print_model_LP
        "with nonlinear terms." % (constraint_data.name)) ValueError: Cannot write legal LP file.  Constraint '1.max_pcr_power[1]' has a
    body with nonlinear terms.</p>
  </blockquote>
  
  <p>I thought, that the problem may lay within the nested formulation of the constraint, i.e. the combination of sum and exponential terms. Therefore, I put the sum()-term into a separate variable. This didn't change the core the characteristic of the nonlinear constraint, so that the error stayed the same. My other suspicion was, that the problem lays within the gurobi solver. So i tried to utilize ipopt, which produced the follwing error message:</p>
  
  <blockquote>
    <p>Error evaluating constraint 1: can't evaluate pow'(0,0.5). ERROR:
    Solver (ipopt) returned non-zero return code (1) ERROR: See the solver
    log above for diagnostic information. Exception encountered. Scenario
    tree manager attempting to shut down. Traceback (most recent call
    last):   File "C:\Users\theil\Anaconda3\Scripts\runef-script.py", line
    5, in 
        sys.exit(pyomo.pysp.ef_writer_script.main())   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\pysp\ef_writer_script.py",
    line 863, in main
        traceback=options.traceback)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\pysp\util\misc.py",
    line 344, in launch_command
        rc = command(options, *cmd_args, **cmd_kwds)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\pysp\ef_writer_script.py",
    line 748, in runef
        ef.solve()   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\pysp\ef_writer_script.py",
    line 434, in solve
        **solve_kwds)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\opt\parallel\manager.py",
    line 122, in queue
        return self._perform_queue(ah, *args, **kwds)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\opt\parallel\local.py",
    line 59, in _perform_queue
        results = opt.solve(*args, **kwds)   File "C:\Users\theil\Anaconda3\lib\site-packages\pyomo\opt\base\solvers.py",
    line 626, in solve
        "Solver (%s) did not exit normally" % self.name) pyutilib.common._exceptions.ApplicationError: Solver (ipopt) did not
    exit normally</p>
  </blockquote>
  
  <p>I am wondering now, if my mistake lays within the formulation of the constraint or the way i utilize the solver. Otherwise I have to simplify my problem to make it solvable.</p>
  
  <p>I would be glad, if you can point me in the right direction. Thank you!</p>
  
  <p>Best regards
  Philipp</p>