@itsme
I've tried numerous times to get the Maple/Matlab link to work. I've settled on using the toolbox, which works great for my condition, but crashes every so often.
Matlab stores the information much more efficiently. For 50k systems of solutions, each with 20 variables, Matlab takes 7.63MB in memory to store this system in a Dataset (calculated using this code). Maple takes ~300MB to store the same data in list form (calculated using maple('evalf(kernelopts(bytesused)/1024/1024)')). From this, I can conclude that I should create a memory dump from Maple to Matlab.
For the Maple to Matlab dump, each system of equation solves in the form:
Ans = {{ICE_T = 10, BAT_P = 30, EM2_T = 50, EM2_W = 30 ....}, {ICE_T = 10, BAT_P = 30, EM2_T = 50, EM2_W = 40....}}
I parse this in Matlab and store it in a dataset array:
ICE_T BAT_P EM2_T EM2_W ....
10 30 50 30
10 30 50 40
...
As for code, this is a simplified version of what I'm doing. The following is a matlab script that calls the maple solver. I've walked through the code in bold.
%Solve for the system symbolically. Create a function, where inputs are the points are the grid values %where the system is to be evaluated.
maple('symb_sol:=unapply(eliminate(SystemEquations_NoDriver,NotDriverVars),[DriverVars])');
while tt < num_sys_eqs
%Increment and define solve range indexes
tt_min = tt+1;
tt_max = tt_min + Max_AnsVec_Size-1;
tt = tt_max;
if tt_max > num_sys_eqs
tt_max = num_sys_eqs;
end
%(Re)initalize answer vector (Free memory)
if tt_min == 1 || tt_max == num_sys_eqs
maple(['Ans:= Vector[column](',num2str(tt_max-tt_min+1),');']);
else
maple(['Ans:= Ans * 0']); %Free up the memory in the Answer vector
maple(['Ans:= Vector[column](',num2str(tt_max-tt_min+1),');']); %Initalize answer vector as the size of the block
end
disp(sprintf('Solving system %i to %i of %i',tt_min,tt_max,num_sys_eqs));
%Load points to evaluate symbolic function into maple
maple(['Contolpoints_vector := ', MatlabMatrix_toMapleMatrix(double(ControlPoints_Dataset(tt_min:tt_max,2:end))) ]);
maple(['BB_timevec := ', MatlabVec_to_MapleVec(ControlPoints_Dataset.time(tt_min:tt_max))]);
maple(['for i from 1 to Size(BB_timevec)[2] do ' ...
'BB_Driverlist_set(i):= convert(Equate(collected_component_input_eqs,Contolpoints_vector[i]),set) union {time = BB_timevec[i]}; ' ...
'od;']);
%Plug drivers into solver
maple(['' ...
'for i from 1 to Size(BB_timevec)[2] do ' ...
'Ans[i]:= symb_sol(Contolpoints_vector[i][])[1] union BB_Driverlist_set(i); ' ...
'od;']);
%Dump solutions
if tt_min == 1 %First one
LUT_initialized = 1;
%MapleToMatlabMemoryDump takes the maple list of solutions, and makes it into a matlab dataset
VehicleStateSpace_LUT = MapleToMatlabMemoryDump('Ans',int32(maple('Size(Ans)[1]')));
else
VehicleStateSpace_LUT = cat(1,VehicleStateSpace_LUT,MapleToMatlabMemoryDump('Ans',int32(maple('Size(Ans)[1]'))));
end
end
I've also tried passing the variable in one at at time instead of making a solver range of 50000. This approach still causes crashes.
I'm open to any suggestions!
Edit:
If I add
disp(sprintf('Maple memory: %.0f MB', int32(maple('kernelopts(bytesalloc)/1024/1024'))))
inside the loop. It shows Maple allocating more and more memory. It doesn't plateau as I would expect.