From d1ba1015b542fd0dde268dac0e05073483245ab0 Mon Sep 17 00:00:00 2001 From: Olivier Cots Date: Mon, 10 Jun 2024 17:27:28 +0200 Subject: [PATCH] foo --- src/CTBase.jl | 1 + src/onepass.jl | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/CTBase.jl b/src/CTBase.jl index b56e1b63..605c4d9d 100644 --- a/src/CTBase.jl +++ b/src/CTBase.jl @@ -246,6 +246,7 @@ export BoundaryConstraint, StateConstraint, ControlConstraint, MixedConstraint, # model export OptimalControlModel export Model +export __OCPModel # redirection to Model to avoir confusion with other Model functions from other packages. Due to @def macro export variable!, time!, constraint!, dynamics!, objective!, state!, control!, remove_constraint!, constraint export is_time_independent, is_time_dependent, is_min, is_max, is_variable_dependent, is_variable_independent export nlp_constraints, constraints_labels diff --git a/src/onepass.jl b/src/onepass.jl index e07f98ba..37cf35d1 100644 --- a/src/onepass.jl +++ b/src/onepass.jl @@ -430,6 +430,11 @@ p_bolza!(p, ocp, e1, e2, type; log=false) = begin end, p.lnum, p.line) end +# redirection to Model() to avoid confusion with other functions Model from other packages +function __OCPModel(args...; kwargs...) + return CTBase.Model(args...; kwargs...) +end + """ $(TYPEDSIGNATURES) @@ -464,10 +469,10 @@ macro def(ocp, e, log=false) p = ParsingInfo(); p.t_dep = p0.t_dep; p.v = p0.v code = parse!(p, ocp, e; log=log) init = @match (__t_dep(p), __v_dep(p)) begin - (false, false) => :( $ocp = Model() ) - (true , false) => :( $ocp = Model(autonomous=false) ) - (false, true ) => :( $ocp = Model(variable=true) ) - _ => :( $ocp = Model(autonomous=false, variable=true) ) + (false, false) => :( $ocp = __OCPModel() ) + (true , false) => :( $ocp = __OCPModel(autonomous=false) ) + (false, true ) => :( $ocp = __OCPModel(variable=true) ) + _ => :( $ocp = __OCPModel(autonomous=false, variable=true) ) end ee = QuoteNode(e) code = Expr(:block, init, code, :( $ocp.model_expression=$ee ), :( $ocp )) # todo: remove returned ocp value?