This is a master's graduation project where a novel Dynamic Programming (DP) based algorithm that used to minimize the battery consumption when driving electric vehicles is developed. The project is coded in C and compiled into S-function which can be used in Matlab/Simulink.
C++ 0.26%C 64.33%MATLAB 10.82%Makefile 18.26%CMake 6.34%
Hardware Information (that used to evaluate the solver):
CPU: i7-8550U
RAM: 16GB
System type: 64-bit Winddows 10 operating system
File Explanations:
./MatlabFiles
/createSfunc.m: Integrate the C function that contains the DP algorithm (MagicBox) into a Simulink model
/inputSolver.m: Input parameters, including model parameters and constraints, and an example scenario.
/showResult.m: Figures of the generated solutions.
/ModelSolver.slx: Simulink model of the DP solver
./inc (header files)
./src (source files)
/SolverStruct.h: Public structures used in the entire program.
/SolverAlgorithm.h/c: The main DP algorithm - function MagicBox connects everything.
/MathFunction.h/c: General mathematical functions (interpolation, sorting, etc.).
/SystemDynamics.h/c: System dynamics calculation.
/BoundaryLine.h/c: Boundary line calculation for the vechile speed.
/AdaptiveGrid.h/c: Generate state boxes for the adaptive state grid method.
/PrintResult.h/c (Not used): Record the output results into a txt file.
./main.c: It is only used when running the codes on the C platform.
Example of using this solver
Run createSfunc.m to compile the C codes into a S-function.
Run inputSolver.m to set the input parameters and the input scenario.
Run ModelSolver.slx to generate the solutions.
Run showResult.m to see the results.
Important Notes:
The S-function has to be recompiled when the following parameter(s) is(are) changed:
Grid sizes: Nv, Nf, Nt, Nq (in inputSolver.m) / NV, NF, NT, NQ (in SolverStruct.c).
Length of horizon: Nhrz (in inputSolver.m)/ HORIZON (in SolverStruct.c)
Number of iterations: NUM_IDP (in SolverStruct.c)
Shrinking rate: GAMMA (in SolverStruct.c)
The parameters of the Grid sizes and the Length of horizon need to be kept the same in inputSolver.m and SolverStruct.c.
The boundary line calculation highly depends on the model equations, so it may not be easy to modify this part when the models are very different. It can be turned off by using '#define NOBOUND' in SolverStruct.c.
To the best of my knowledge, the C codes does not work with Visual Studio compiler due to the use of Variable Length Array (VLA).