static void TestHS71() { Console.WriteLine(); Console.WriteLine("### Test Problem: Hock-Schittkowski #71"); var problem = new OptimizationProblem(); var x1 = new Variable("x1", 1, 1, 5); var x2 = new Variable("x2", 2, 1, 5); var x3 = new Variable("x3", 5, 1, 5); var x4 = new Variable("x4", 1, 1, 5); problem.AddVariables(x1, x2, x3, x4); problem.ObjectiveFunction = x1 * x4 * Sym.Par(x1 + x2 + x3) + x3; problem.AddInequalityConstraints(new Constraint(x1 * x2 * x3 * x4, ConstraintComparisonOperator.GreaterThanOrEqual, 25)); problem.AddConstraints((Sym.Pow(x1, 2) + Sym.Pow(x2, 2) + Sym.Pow(x3, 2) + Sym.Pow(x4, 2)).IsEqualTo(40)); // var solver = new IpoptSolver(); solver.OnLog += Console.WriteLine; solver.Solve(problem); Console.WriteLine(x1.WriteReport()); Console.WriteLine(x2.WriteReport()); Console.WriteLine(x3.WriteReport()); Console.WriteLine(x4.WriteReport()); }
OptimizationSolver(OptimizationProblem optimizationProblem, OptimizationSubstitutions optimizationSubstitutions) { if (optimizationProblem == null) { throw new ArgumentNullException("optimizationProblem"); } if (optimizationSubstitutions == null) { throw new ArgumentNullException("optimizationSubstitutions"); } this.optimizationProblem = optimizationProblem; this.optimizationSubstitutions = optimizationSubstitutions; this.solver = new IpoptSolver(optimizationProblem.Problem.Substitute(optimizationSubstitutions.Substitutions), new Settings()); }
public PythonEnvironmentModule(IEventAggregator aggregator, IEntityManagerViewModel entityManager, IThermodynamicSystemImporter importer, IChartViewModelFactory chartFactory, IFlowsheetEntityEditorFactory flowsheetFactory, IPureComponentPropertyDatabase pureDB, IThermodynamicSystemViewModelFactory thermoEditorFactory ) { _aggregator = aggregator; _entityManager = entityManager; _importer = importer; _chartFactory = chartFactory; _flowsheetFactory = flowsheetFactory; _pyEngine = Python.CreateEngine(); _pyScope = _pyEngine.CreateScope(); _pureComponentDB = pureDB; _thermoEditorFactory = thermoEditorFactory; _pyScope.SetVariable("_host", this); _pyScope.SetVariable("Items", _entityManager); _pyEngine.SetSearchPaths(new List <string> { Environment.CurrentDirectory }); var pc = HostingHelpers.GetLanguageContext(_pyEngine) as PythonContext; var hooks = pc.SystemState.Get__dict__()["path_hooks"] as List; hooks.Clear(); Run("import sys"); Run("import clr"); Run("clr.AddReferenceToFile(\"OpenFMSL.Core.dll\")"); Run("clr.AddReferenceToFile(\"OpenFMSL.Contracts.dll\")"); Run("from OpenFMSL.Core.Expressions import *"); Run("from OpenFMSL.Core.Flowsheeting import *"); Run("from OpenFMSL.Core.Flowsheeting.Documentation import *"); Run("from OpenFMSL.Core.Numerics import *"); Run("from OpenFMSL.Core.Numerics.Solvers import *"); Run("from OpenFMSL.Core.UnitsOfMeasure import *"); Run("from OpenFMSL.Core.ModelLibrary import *"); Run("from OpenFMSL.Core.Thermodynamics import *"); Run("from OpenFMSL.Contracts.Entities import *"); Run("from OpenFMSL.Contracts.Infrastructure.Reporting import *"); Run("from System import Math"); Run("sys.stdout=_host"); Run("runFile= _host.RunFile"); Run("run= _host.RunEntity"); Run("pause= _host.WaitThread"); Run("CreateThermo= _host.LoadThermodynamicSystem"); _pureComponentDB.SetLogCallback(Write); ipopt = new IpoptSolver(); ipopt.OnLog = (x) => Write(" " + x + Environment.NewLine); _pyScope.SetVariable("_ipopt", ipopt); _pyScope.SetVariable("Database", _pureComponentDB); newton = new Newton(); newton.OnLog = (x) => Write(" " + x + Environment.NewLine); newton.OnLogDebug = (x) => Write(x + Environment.NewLine); newton.OnLogError = (x) => Write("!!! " + x + Environment.NewLine); newton.OnLogSuccess = (x) => Write("+++ " + x + Environment.NewLine); newton.OnLogWarning = (x) => Write("*** " + x + Environment.NewLine); newton.OnLogInfo = (x) => Write("--- " + x + Environment.NewLine); _pyScope.SetVariable("_newton", newton); var flash = new FlashRoutines(newton); _pyScope.SetVariable("_flash", flash); decomp = new Decomposer(); decomp.OnLog = (x) => Write(" " + x + Environment.NewLine); decomp.OnLogDebug = (x) => Write(x + Environment.NewLine); decomp.OnLogError = (x) => Write("!!! " + x + Environment.NewLine); decomp.OnLogSuccess = (x) => Write("+++ " + x + Environment.NewLine); decomp.OnLogWarning = (x) => Write("*** " + x + Environment.NewLine); decomp.OnLogInfo = (x) => Write("--- " + x + Environment.NewLine); _pyScope.SetVariable("_decomp", decomp); Run("solve= _host.Solve"); Run("decomp= _host.Decompose"); Run("report= _host.Report"); Run("show= _host.Show"); Run("check= _host.Check"); Run("info= _host.SendLogMessage"); Run("warn= _host.SendWarningMessage"); Run("error= _host.SendErrorMessage"); Run("FlashPT= _flash.CalculateTP"); Run("FlashPZ= _flash.CalculateZP"); Run("status= _host.SendStatusTextChangeMessage"); Run("print 'Python console running..."); }