Skip to content

Commit 446577c

Browse files
committed
First published version
Add readme and license. Change the objective function of the example.
1 parent 8e1f69d commit 446577c

File tree

9 files changed

+105
-14
lines changed

9 files changed

+105
-14
lines changed

LICENSE.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright (c) 2020 Thomas Guillod.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDi
16+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# MATLAB tool for multi-objective optimization (genetic or brute-force)
2+
3+
This **MATLAB** tool offers different functionalities for multi-objective optimization:
4+
* Offer a **common interface** for different solvers
5+
* **Brute force** grid search (exhaustive search)
6+
* MATLAB **single-objective genetic** algoritm ('ga')
7+
* MATLAB **multi-objective genetic** algoritm ('gamultiobj')
8+
* Offer an **abstraction layer** to the MATLAB solver
9+
* Scaling the input variables
10+
* Generating and filtering initial points
11+
* Transforming high-level datastructures ('struct') to low-level ('matrix')
12+
* Generating the low-level inputs required by the solvers
13+
* Allow **vectorized and parallel** evaluation of the functions
14+
* Divide the number of points to be evaluated into chunks
15+
* Evaluate the chunks with parallel computing ('parfor')
16+
* The points inside a chunk are evaluated in a vectorized way
17+
18+
Mathematically, the following optimization problem are solved:
19+
* Multiple variables
20+
* Integer variables
21+
* Upper and lower bounds
22+
* Inequality constraints
23+
* Equality constraints
24+
* Non continuous objective function
25+
* Single-objective or multi-objective goals
26+
27+
Look at the example [run_example.m](run_example.m) which generates the following results:
28+
29+
<p float="middle">
30+
<img src="readme_img/input.png" width="400">
31+
<img src="readme_img/output.png" width="400">
32+
</p>
33+
34+
## Adding Solvers
35+
36+
The code is made to take advantage of optimization methods using vectorized evaluation of the objective function.
37+
Therefore, it would be easy to add support for 'patternsearch', 'particleswarm', or 'paretosearch'.
38+
Adding support for non vectorized solvers ('fmincon', 'fminbnd', or 'fminsearch') is possible but less interesting.
39+
40+
## Compatibility
41+
42+
* Tested with MATLAB R2018b.
43+
* Required the gads_toolbox (for contour detection).
44+
* Required the optimization_toolbox (for contour simplification).
45+
* Compatibility with GNU Octave not tested but probably problematic.
46+
47+
## Author
48+
49+
**Thomas Guillod** - [GitHub Profile](https://github.com/otvam)
50+
51+
## License
52+
53+
This project is licensed under the **BSD License**, see [LICENSE.md](LICENSE.md).

get_data.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@
99
% - Integer variables
1010
% - Upper and lower bounds
1111
% - Inequality constraints
12-
% - Inequality constraints
12+
% - Equality constraints
13+
% - Non continuous objective function
1314
% - Single-objective or multi-objective goals
1415
%
1516
% Use the followig strategies:
1617
% - brute force grid search (mixed integer)
1718
% - single-objective genetic algoritm (mixed integer)
1819
% - multi-objective genetic algoritm (continuous variables)
1920
%
20-
% See also RUN_OPTIM, GET_OPTIM, GET_PRE_PROC, GET_SOLUTION.
21+
% The problem solved in this example is trivial and not very interesting.
22+
%
23+
% See also RUN_OPTIM, GET_MULTI_OBJ_OPT, GET_PRE_PROC, GET_SOLUTION.
2124

2225
% Thomas Guillod.
2326
% 2020 - BSD License.
@@ -183,7 +186,7 @@
183186
x_4 = input.x_4;
184187

185188
% compute
186-
y_1 = x_1.^2+x_2.^2+x_3;
189+
y_1 = x_1.^2+(x_2-2).^2+x_3;
187190
y_2 = 0.5*((x_1-2).^2+(x_2+1).^2)+2+x_4;
188191

189192
end

readme_img/input.png

34.7 KB
Loading

readme_img/output.png

33.7 KB
Loading

run_example.m

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function run_example()
33
%
44
% The description of the problem can be found in 'get_data'.
55
%
6-
% See also GET_OPTIM, GET_DATA.
6+
% See also GET_MULTI_OBJ_OPT, GET_DATA.
77

88
% Thomas Guillod.
99
% 2020 - BSD License.
@@ -13,17 +13,29 @@ function run_example()
1313

1414
%% solve brute force optimization
1515
[var_param, solver_param] = get_data('bruteforce');
16-
data_bruteforce = get_optim('bruteforce', var_param, solver_param);
16+
data_bruteforce = get_multi_obj_opt('bruteforce', var_param, solver_param);
1717

1818
%% solve single-objective optimization with genetic algorithm
1919
[var_param, solver_param] = get_data('ga');
20-
data_ga = get_optim('ga', var_param, solver_param);
20+
data_ga = get_multi_obj_opt('ga', var_param, solver_param);
2121

2222
%% solve multi-objective optimization with genetic algorithm
2323
[var_param, solver_param] = get_data('gamultiobj');
24-
data_gamultiobj = get_optim('gamultiobj', var_param, solver_param);
24+
data_gamultiobj = get_multi_obj_opt('gamultiobj', var_param, solver_param);
2525

2626
%% plot the results
27+
figure()
28+
plot3(data_bruteforce.sol.input.x_1, data_bruteforce.sol.input.x_2, data_bruteforce.sol.input.x_3, 'xb')
29+
hold('on')
30+
plot3(data_gamultiobj.sol.input.x_1, data_gamultiobj.sol.input.x_2, data_gamultiobj.sol.input.x_3, 'dr')
31+
plot3(data_ga.sol.input.x_1, data_ga.sol.input.x_2, data_ga.sol.input.x_3, 'og', 'markerfacecolor', 'g')
32+
grid('on')
33+
xlabel('x_{1}')
34+
ylabel('x_{2}')
35+
zlabel('x_{3}')
36+
legend({'bruteforce', 'gamultiobj', 'ga'}, 'Location', 'northeast')
37+
title('Multi-Objective Optimization / Input')
38+
2739
figure()
2840
plot(data_bruteforce.sol.output.y_1, data_bruteforce.sol.output.y_2, 'xb')
2941
hold('on')
@@ -32,8 +44,8 @@ function run_example()
3244
grid('on')
3345
xlabel('y_{1}')
3446
ylabel('y_{2}')
35-
legend('bruteforce', 'gamultiobj', 'ga')
36-
title('Multi-Objective Optimization')
47+
legend({'bruteforce', 'gamultiobj', 'ga'}, 'Location', 'northeast')
48+
title('Multi-Objective Optimization / Output')
3749

3850
end
3951

src/get_optim.m renamed to src/get_multi_obj_opt.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
function data = get_optim(name, var_param, solver_param)
2-
%GET_OPTIM Solve a multi-objective optimization problem with different solvers.
3-
% data = GET_OPTIM(name, var_param, solver_param)
1+
function data = get_multi_obj_opt(name, var_param, solver_param)
2+
%GET_MULTI_OBJ_OPT Solve a multi-objective optimization problem with different solvers.
3+
% data = GET_MULTI_OBJ_OPT(name, var_param, solver_param)
44
% name - name of the problem (string)
55
% var_param - struct with the variable description (struct)
66
% solver_param - struct with the solver data (struct)

src/optim/get_pre_proc.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
% - Scale the 'float' variables with 'lin', 'log', 'exp', 'square', or 'sqrt'
5151
% - Mapping integer variables from [x1, x1, ..., xn] to [1, 2, ..., n]
5252
%
53-
% See also GET_OPTIM, GET_SOLUTION.
53+
% See also GET_MULTI_OBJ_OPT, GET_SOLUTION.
5454

5555
% Thomas Guillod.
5656
% 2020 - BSD License.

src/optim/get_solution.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
% This function performs optimization with different solvers.
5353
% Please note that the 'gamultiobj' cannot deal with integer variables.
5454
%
55-
% See also GET_OPTIM, GET_PRE_PROC, GET_VECTORIZED, BRUTEFORCE, GA GAMULTIOBJ.
55+
% See also GET_MULTI_OBJ_OPT, GET_PRE_PROC, GET_VECTORIZED, BRUTEFORCE, GA GAMULTIOBJ.
5656

5757
% Thomas Guillod.
5858
% 2020 - BSD License.

0 commit comments

Comments
 (0)