1. 25 Sep, 2018 9 commits
    • Tjerk Vreeken's avatar
      Change solver_output from 2-D to 1-D array · b4141be4
      Tjerk Vreeken authored
      Most arrays like lbg/ubg/x0 are already 1-D NumPy arrays if they are not
      a CasADi matrix (MX/DM). It therefore makes sense if the output of the
      solver is also a 1-D array, requiring only a single index to be
      specified to get an element (instead of X[i, 0]).
      
      We ensure that the results dictionary does not present views onto the
      raw solver_output by making a full copy of it first. This is just a
      safeguard though, as it is undefined behavior what should happen if
      someone changes the arrays in the results like that.
      
      Contrary to the previous type annotation, the solver output was already
      a numpy array (a 2-D one, see commit 40875b0a).
      
      Closes #1064
      b4141be4
    • Tjerk Vreeken's avatar
      Rename constraint_relaxation to violation_relaxation · d3e1d3a8
      Tjerk Vreeken authored
      The "constraint_relaxation" name was confusing, as the relaxation is
      only indirectly applied to the eventual hard constraint (i.e. it is
      scaled by the goal's function nominal as well). The term
      violation_relaxation much better describes that this relaxation is
      applied to the violation variables (a.k.a. epsilons).
      d3e1d3a8
    • Tjerk Vreeken's avatar
      Inlude function_range in repr() of StateGoal · efbe3e71
      Tjerk Vreeken authored
      The function_range was already added to the repr() of Goal, but not to
      StateGoal yet. We add it there as well to provide helpful information
      when e.g. the function_range derived from the bounds and the target
      min/max do not agree.
      efbe3e71
    • Tjerk Vreeken's avatar
      Improve goal scale by problem size · e7b7c863
      Tjerk Vreeken authored
      The weighing of goals and path goals should not depend on whether they are
      part of the objective or path objective. To make sure it does not, we have
      to divide both objectives by the _total_ number of subproblem objectives.
      e7b7c863
    • Tjerk Vreeken's avatar
      Fix scale_by_problem_size for path target goals · c103e18f
      Tjerk Vreeken authored
      If a path goal has a target min and/or max, the epsilon will be handled in
      the normal objective (not path_objective()). We therefore have to make
      sure to also divide by the number of time steps after summing an epsilon
      over time if the user has enabled the "scale_by_problem_size" options.
      c103e18f
    • Teresa Piovesan's avatar
      Make fix_minimized_values False for non-default solvers · e9e4ecfa
      Teresa Piovesan authored
      Solvers like Gurobi and CPLEX cannot handle quadratic equality
      constraints. The default value for fix_minimized_values being True might
      therefore lead to issues if more than one minimization goal is present.
      
      To provide backwards compatibility, we make sure that the default value
      of True is preserverd for IPOPT and BONMIN. Only in the case that the
      user overrides the solver will the default value be False.
      e9e4ecfa
    • Teresa Piovesan's avatar
      Handle fix_minimized_values for normal goals · 8ece605d
      Teresa Piovesan authored
      The fix_minimized_values goal programming option only affected path
      goals. The same logic should however apply to normal goals.
      8ece605d
    • Teresa Piovesan's avatar
      Fix goal relaxation with minimization goals · f7d3b695
      Teresa Piovesan authored
      The default value for fix_minimized_values is True, and therefore a goal
      relaxation on minimization goals would result in two constraints, one of
      which would be possibly non-convex.
      
      The idea behind fix_minimized_values is to impose a possibly non-convex
      _equality_ constraint for interior point methods, to avoid numerical
      issues with small slack variables. We therefore now check if the goal
      has any relaxation, in which case we impose a single inequality
      constraint instead of a single equality constraint.
      f7d3b695
    • Tjerk Vreeken's avatar
      ad7366d0
  2. 03 Sep, 2018 1 commit
  3. 27 Aug, 2018 1 commit
  4. 24 Aug, 2018 14 commits
    • Tjerk Vreeken's avatar
      Simulation: opt-in partial workaround for delay() · 1ca2c04d
      Tjerk Vreeken authored
      A workaround is added to support a delay of zero (or make delay expression
      behave as such). By default, this workaround is disabled. The user has to
      explicitly set "_force_zero_delay" to True to enable it.
      1ca2c04d
    • Teresa Piovesan's avatar
      Doc fix goal function range/nominals · f413630d
      Teresa Piovesan authored
      Add explanation on how the function range and function nominal are used
      for minimization goals vs target goals. This also fixes consistency with
      the check introduced in commit e9f500d7.
      f413630d
    • Jorn Baayen's avatar
      Return ca.MX(0) by default in objectives/residuals · db12302f
      Jorn Baayen authored
      Because `ca.MX() + 1 = ca.MX()`, returning an empty symbol could be
      confusing if people override e.g. self.objective().
      db12302f
    • Jorn Baayen's avatar
      CollInt: Handle MX objective with 0x0 shape · 3bb2217b
      Jorn Baayen authored
      If self.objective() returns a 0x0 MX, do not use it as a base to add
      path objectives to, as the result would still be 0x0.
      
      This is due to the fact that `ca.MX() + 1 = ca.MX()`.
      3bb2217b
    • Olav van Duin's avatar
      Only do duplicate parameter check for PI-XML · 094cdac4
      Olav van Duin authored
      Before, we would (optionally) check if a parameter read from the PI-XML
      files (rtcParameterConfig*.xml) was already set before. This would lead
      to a warning if a parameter occurred in multiple PI-XML files, but also
      if a value was already present in the model file(s). The latter type of
      warning is unnecessary as we expect parameters to be updated at runtime.
      This commit makes sure that only warnings are raised for duplicates
      found in the PI-XML files.
      094cdac4
    • Tjerk Vreeken's avatar
      Improve goal function range vs. targets check · f97a0ab4
      Tjerk Vreeken authored
      We now check that the target min/max are not equal to the function range
      lower bound/upper bound respectively as well.
      
      A target minimum equal to the lower bound of the function range does not
      make any sense, as the corresponding epsilon is then free (and will
      therefore always become zero). Effectively, the goal will behave as a
      critical goal, and users should use those instead if such behavior is
      desired.
      f97a0ab4
    • Tjerk Vreeken's avatar
      Disallow function_range for minimization goals · 5f3e17df
      Tjerk Vreeken authored
      Minimization goals only use the function nominal for scaling. Requiring
      the user to specify a function range is misleading.
      
      Closes #1051
      5f3e17df
    • Olav van Duin's avatar
      Fix flooring of dates/times in PI-XML import · a2f00aff
      Olav van Duin authored
      Before, we would floor based on the base time (midnight 1-1-1970). This
      would mean that having a start date of e.g. 09:35 and a time step of
      00:15 did not work well together. The start date would get rounded down
      to 09:30 instead of the desired 09:35. This commit makes sure that such
      cases are handled correctly, but that rounding is still performed (e.g.
      09:51 will get rounded down to 09:50).
      
      Closes #1020
      a2f00aff
    • Teresa Piovesan's avatar
      Doc fix type of scale_by_problem_size · 9ce64c09
      Teresa Piovesan authored
      9ce64c09
    • Tjerk Vreeken's avatar
      bde691b4
    • Tjerk Vreeken's avatar
      Fix discrepancy between goal and path goal scaling · cd33c423
      Tjerk Vreeken authored
      Path goals were not divided by the number of time steps, meaning that
      formulting a problem with a bunch of normal goals using state_at() (one
      for each time step) and a path goal would lead to different objectives and
      results.
      
      To fix the discrepancy, we disable the division by the number of
      goals/time steps by default. This is conservative in the sense that we
      then guarantee at least as accurate a result as before this commit. For
      very tricky/badly scaled problems it may however lead to convergence
      issues.
      
      Should scaling with the problem size be desired, the new
      "scale_by_problem_size" goal programming option can be set to True.
      
      Closes #1046
      cd33c423
    • Tjerk Vreeken's avatar
      Fix theta parameter availability · 4df6d5bb
      Tjerk Vreeken authored
      When using the HomotopyMixin, a call to parameters() would fail in
      pre(), because the parameter __theta is only initialized in the
      optimize() call.
      
      Also add a comment explaining why we do not initialize theta right away.
      4df6d5bb
    • Tjerk Vreeken's avatar
      Fix parameter inlining for path objective/constraints · 0b6c34f7
      Tjerk Vreeken authored
      When using goal programming, parameters would only get inlined in the
      first priority (i.e. the first call to the transcribe() method).
      
      Note that regular objective and constraints cannot/should not refer to
      parameters with the variable() or state() methods (which return an MX
      symbol), and instead always rely on state_at() and parameters(). The
      latter two always return a numberic value, and we therefore we do not
      need to perform any inlining on the regular objective and constraints.
      0b6c34f7
    • Tjerk Vreeken's avatar
      Fix parameter inlining for delayed expressions · fa49e368
      Tjerk Vreeken authored
      If we inline a parameter, we have to make sure to also inline it in the
      delay expression and duration. The latter was already taken care of
      somewhere else in the code, but has been moved near the newly added
      processing of the delay expressions.
      
      Note that evaluating the delayed_feedback_function() could still
      give non-NaN results even if inputs were missing, which made this bug
      somewhat hard to encounter and track down.
      The fact that this happens is due to the expand() call; if we would call
      the original MX function, it would complain about free variables. Why
      CasADi does not always return NaN for outputs of which not all inputs
      were specified is unknown though.
      fa49e368
  5. 04 Aug, 2018 3 commits
  6. 14 Jul, 2018 3 commits
    • Tjerk Vreeken's avatar
      Fix goal constraint min/max bounds consistency · 40567dba
      Tjerk Vreeken authored
      It could happen that lower (later) priority goals for an already
      constrained state would result in an answer that would be slightly
      outside the hard constraints due to feasibilty tolerances.
      When combining the soft constraint and existing hard constraint in a new
      hard constraint, the existing hard constraint values could be shifted,
      basically enforcing a solution that may or may not be feasible.
      
      An example for a typical state with goals at multiple priorities:
      
      +----------+------------+------------+
      | Priority | Target Min | Target Max |
      +----------+------------+------------+
      |        1 |        0.0 |        0.7 |
      |        2 |        0.7 |        0.7 |
      +----------+------------+------------+
      
      The first priority could end up with a hard constraint exactly matching,
      i.e. (0.0, 0.7). Exaggerating the numerical differences that can occur,
      the second priority could end up with a value of 0.701 for the state in
      question.
      What would happen before this commit is that we would calculate a new
      hard constraint (0.701, 0.7). This would then be corrected to (0.701,
      0.701), which would then replace the original hard constraint.
      
      It is safer to keep enforcing the old hard constraint (which led to the
      solution of 0.701) making the new constraint (0.7, 0.7). This is the
      behavior that this commit makes happen.
      40567dba
    • Tjerk Vreeken's avatar
      Fix goal consistency and monotonicity checks · 4b82a3ec
      Tjerk Vreeken authored
      If a goal had both a target min and a target max, the latter would not
      get checked for consistency due to the "elif" instead of "if".
      
      The check for target min/max exceedence of the function range compared
      the True/False value returned by has_target_* instead of the actual
      target min/max value.
      
      Furthermore, the monotonicity checks path goals were behind the option
      flag, but those of (normal) goals were not.
      4b82a3ec
    • Tjerk Vreeken's avatar
      Fix unwanted conversion to MX in substitute calls · 80c8656b
      Tjerk Vreeken authored
      It could happen that a DM expression would be converted to an MX
      expression, which would then later confuse the solver (e.g. when the
      values are the lower/upper bounds of the constraints).
      
      One example is that when passing as expr a 15x1 DM array of all 293.55
      values, the resulting value would be "MX(all_293.65(15x1))". This in
      turn would confuse the solver call, resulting in an exception.
      80c8656b
  7. 18 Jun, 2018 1 commit
    • Tjerk Vreeken's avatar
      Fix history extrapolation for delayed expressions · 1f64e529
      Tjerk Vreeken authored
      The supposed block interpolation that was in place does not work as
      suggested. It would only properly extrapolate values if the corresponding
      output x-coordinate was outside of the range of input x-coordinates. It
      would however not extrapolate or interpolate like that with NaNs present.
      For example (y-coordinates of input and output only):
                [4,0, 4.0] --> [4.0, 4.0, 4.0, 4.0]
      [nan, nan, 4.0, 4.0] --> [nan, nan, 4.0, 4.0]
      1f64e529
  8. 14 Jun, 2018 2 commits
  9. 11 Jun, 2018 3 commits
    • Tjerk Vreeken's avatar
      Rename variable for delayed expression · b829e17d
      Tjerk Vreeken authored
      In the past the delayed expression could only be a variable. Nowadays it
      is allowed to be an arbitrary expression. This commit renames the variable
      and logging message accordingly.
      b829e17d
    • Tjerk Vreeken's avatar
      Fix parameter substitution in delay calculation · ea250558
      Tjerk Vreeken authored
      The symbolic_parameters contains only a subset of all parameters, or
      possibly no parameters at all. The inlining of "constant" parameters
      resulting in this change was already committed a few months ago in
      36ef52dd. To properly substitute all parameters, we therefore substitute
      both the symbolic and constant parameters.
      ea250558
    • Tjerk Vreeken's avatar
      Fix delayed feedback handling for multiple delays · ba08c0e2
      Tjerk Vreeken authored
      When more than one delay variable is present, multiple calculations would
      fail.
      
      The division for history calculations would fail because of mismatching
      shapes. By default, NumPy would try to divide every row, and therefore
      the number of columns should be equal. In our case, we want to divide
      every column by some other list of values, so we have to use [:, None] to
      index it. Furthermore, the calculation has been rewritten to use np.diff for
      clarity/simplicity.
      
      The delayed_feedback_function returns a list of values, and these should
      not be unpacked.
      
      Lastly, the truth value of an array is not allowed either, and requires
      either all/any to reduce it to a single boolean first.
      ba08c0e2
  10. 31 May, 2018 1 commit
    • Jesse VanderWees's avatar
      Make OrderedSet pickleable and deepcopyable · 4e518571
      Jesse VanderWees authored
      In some implementations of rtc-tools, users might want to pickle or
      deepcopy rtc data structures, e.g. the AliasRelation returned
      by results(). The linked list underlying the OrderedSet class (used by
      AliasRelation and others) would produce max depth recursion errors with
      the default behaviour, so we define methods __getstate__ and __setstate__
      to keep behaviour as expected.
      4e518571
  11. 29 May, 2018 1 commit
    • Tjerk Vreeken's avatar
      Log message when expanding MX graphs · 3383a206
      Tjerk Vreeken authored
      This way users can check whether they set the option correctly. Of
      course, in most cases you do not want to be notified, which is why it
      has debug level.
      3383a206
  12. 28 May, 2018 1 commit
    • Tjerk Vreeken's avatar
      Fix lingering reference to GPL · 3038aa6c
      Tjerk Vreeken authored
      Contrary to the GPL, the LGPL does not require printing a notification
      to the screen. We therefore only log the version number, which could
      still be useful information.
      
      Most other references to GPL were taken care of in bc4ebe74, but this
      one was missed. Note that a similar message for optimization problems
      was already addressed in said commit.
      3038aa6c