Skip to content

Commit

Permalink
Tidied up the MATLAB code. Updated the MATLAB plots. Updated the docu…
Browse files Browse the repository at this point in the history
…mentation.
  • Loading branch information
rlefringhausen committed May 17, 2024
1 parent 8f6a08e commit e871b3c
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 144 deletions.
2 changes: 1 addition & 1 deletion Julia/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Julia
[![Dev](https://img.shields.io/badge/docs-latest-blue.svg)](https://TUM-ITR.github.io/PGopt)
[![Dev](https://img.shields.io/badge/docs-stable-blue?logo=Julia&logoColor=white)](https://TUM-ITR.github.io/PGopt)

This folder contains the Julia implementation of `PGopt`, which does not require proprietary software. The open-source solver [Altro](https://github.com/RoboticExplorationLab/Altro.jl) is used for the optimization. The results presented in the paper were generated with this version, and the software reproduces these results exactly.

Expand Down
4 changes: 2 additions & 2 deletions Julia/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ This document describes the Julia implementation of `PGopt`, which does not requ
Besides the Julia implementation, there is also a MATLAB implementation, which is more general and allows arbitrary cost functions $J_H(u_{1:H},x_{1:H},y_{1:H})$, measurement functions $y=g(x,u)$, and constraints $h(u_{1:H},x_{1:H},y_{1:H})$. Further information can be found [here](https://github.com/TUM-ITR/PGopt/tree/main/MATLAB).

## Installation
PGopt can be installed using the Julia package manager. Start a Pkg REPL (press `]` in a Julia REPL), and install PGopt via
`PGopt` can be installed using the Julia package manager. Start a Pkg REPL (press `]` in a Julia REPL), and install `PGopt` via
```
pkg> add https://github.com/TUM-ITR/PGopt:Julia
pkg>add https://github.com/TUM-ITR/PGopt:Julia
```

Alternatively, to inspect the source code more easily, download the source code from [GitHub](https://github.com/TUM-ITR/PGopt). Navigate to the folder `PGopt/Julia`, start a Pkg REPL (press `]` in a Julia REPL), and install the dependencies via
Expand Down
9 changes: 6 additions & 3 deletions MATLAB/examples/PG_OCP_generic_basis_functions.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
% This code produces results for the optimal control approach with generic basis functions similar to the ones given in Section V-B (Fig. 3) of the paper
% "Learning-Based Optimal Control with Performance Guarantees for Unknown Systems with Latent States", available as pre-print on arXiv: https://arxiv.org/abs/2303.17963.
% Since the Julia implementation was used for the results in the paper, the results are not exactly reproduced due to different random numbers.
% Since the Julia implementation was used for the results in the paper, the results are not exactly reproduced.

% Clear
clear;
Expand Down Expand Up @@ -170,7 +170,7 @@

%% Test the learned models.
% Test the models with the test data by simulating it forward in time.
test_prediction(PG_samples, phi_sampling, g, R, 10, u_test, y_test);
% test_prediction(PG_samples, phi_sampling, g, R, 10, u_test, y_test);

%% Plot autocorrelation.
% plot_autocorrelation(PG_samples, 'max_lag', 100)
Expand Down Expand Up @@ -198,8 +198,11 @@
% This function is only used for the optimization as it is less efficient.
phi = @(x, u) phi_opt(n_phi, n_z, L, j_vec, x, u);

% Ipopt options
Ipopt_options = struct('linear_solver', 'ma57', 'max_iter', 10000);

% Solve the PG OCP.
[u_opt, x_opt, y_opt, J_opt, solve_successful, ~, ~] = solve_PG_OCP(PG_samples, phi, g, R, H, cost_function, scenario_constraints, input_constraints, 'J_u', true, 'K_pre_solve', 10);
[u_opt, x_opt, y_opt, J_opt, solve_successful, ~, ~] = solve_PG_OCP(PG_samples, phi, g, R, H, cost_function, scenario_constraints, input_constraints, 'J_u', true, 'K_pre_solve', 5, 'solver_opts', Ipopt_options);

%% Test solution
if solve_successful
Expand Down
7 changes: 5 additions & 2 deletions MATLAB/examples/PG_OCP_known_basis_functions.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,14 @@
% Confidence parameter for the theoretical guarantees
beta = 0.01;

% Ipopt options
Ipopt_options = struct('linear_solver', 'ma57', 'max_iter', 10000);

% Solve the PG OCP.
% [u_opt, x_opt, y_opt, J_opt, solve_successful, ~, ~] = solve_PG_OCP(PG_samples, phi, g, R, H, cost_function, scenario_constraints, input_constraints, 'J_u', true, 'K_pre_solve', 10);
% [u_opt, x_opt, y_opt, J_opt, solve_successful, ~, ~] = solve_PG_OCP(PG_samples, phi, g, R, H, cost_function, scenario_constraints, input_constraints, 'J_u', true, 'K_pre_solve', 5);

% Solve the PG OCP and determine complexity s and max constraint violation probability via greedy algorithm.
[u_opt, x_opt, y_opt, J_opt, solve_successful, s, epsilon_prob, epsilon_perc, time_first_solve, time_guarantees, num_failed_optimizations] = solve_PG_OCP_greedy_guarantees(PG_samples, phi, g, R, H, cost_function, scenario_constraints, input_constraints, beta, 'J_u', true, 'K_pre_solve', 10);
[u_opt, x_opt, y_opt, J_opt, solve_successful, s, epsilon_prob, epsilon_perc, time_first_solve, time_guarantees, num_failed_optimizations] = solve_PG_OCP_greedy_guarantees(PG_samples, phi, g, R, H, cost_function, scenario_constraints, input_constraints, beta, 'J_u', true, 'K_pre_solve', 5, 'solver_opts', Ipopt_options);

%% Test solution
if solve_successful
Expand Down
Loading

0 comments on commit e871b3c

Please sign in to comment.