Created
May 29, 2019 17:17
-
-
Save alphaville/5c7c4c4980b3aa6d06a553c219907a1f to your computer and use it in GitHub Desktop.
Example of using opengen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import casadi.casadi as cs | |
| import opengen as og | |
| u = cs.SX.sym("u", 5) | |
| p = cs.SX.sym("p", 2) | |
| # COST FUNCTION | |
| phi = og.functions.rosenbrock(u, p) | |
| # PENALTY-TYPE CONSTRAINTS | |
| c = cs.vertcat(1.5*u[0] - u[1], u[2] - u[3]) | |
| # CONSTRAINTS | |
| xmin = [-2.0, -2.0, -2.0, -2.0, -2.0] | |
| xmax = [2.0, 2.0, 2.0, 2.0, 2.0] | |
| bounds = og.constraints.Rectangle(xmin, xmax) | |
| # CONFIGURATION... | |
| problem = og.builder.Problem(u, p, phi) \ | |
| .with_penalty_constraints(c) \ | |
| .with_constraints(bounds) | |
| meta = og.config.OptimizerMeta() \ | |
| .with_version("0.0.2") \ | |
| .with_authors(["P. Sopasakis", "E. Fresk"]) \ | |
| .with_licence("CC4.0-By") \ | |
| .with_optimizer_name("wow_optimizer") | |
| build_config = og.config.BuildConfiguration() \ | |
| .with_rebuild(False) \ | |
| .with_build_mode("debug") \ | |
| .with_build_directory("python_codegen_builds") \ | |
| .with_open_version("0.3.2") | |
| solver_config = og.config.SolverConfiguration() \ | |
| .with_lfbgs_memory(15) \ | |
| .with_tolerance(1e-5) \ | |
| .with_max_inner_iterations(155) \ | |
| .with_constraints_tolerance(1e-4) \ | |
| .with_max_outer_iterations(15) \ | |
| .with_penalty_weight_update_factor(8.0) \ | |
| .with_initial_penalty_weights([20.0, 5.0]) \ | |
| .with_max_duration_micros(3000) | |
| # BUILD CODE | |
| og.builder.OpEnOptimizerBuilder(problem, | |
| metadata=meta, | |
| build_configuration=build_config, | |
| solver_configuration=solver_config) \ | |
| .with_generate_not_build_flag(False) \ | |
| .build() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment