0001 function getInstructions(obj, cppobj, get)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 global ACADO_;
0032
0033 if (get == 'B')
0034
0035 fprintf(cppobj.fileMEX,sprintf(' OptimizationAlgorithm %s(%s);\n',obj.name, obj.ocp.name));
0036
0037 obj.getSetInitInstructions(cppobj);
0038
0039 fprintf(cppobj.fileMEX,sprintf(' returnValue returnvalue = %s.solve();\n', obj.name));
0040
0041 fprintf(cppobj.fileMEX,'\n');
0042
0043 fprintf(cppobj.fileMEX,' VariablesGrid out_states; \n');
0044 fprintf(cppobj.fileMEX,' VariablesGrid out_parameters; \n');
0045 fprintf(cppobj.fileMEX,' VariablesGrid out_controls; \n');
0046 fprintf(cppobj.fileMEX,' VariablesGrid out_disturbances; \n');
0047 fprintf(cppobj.fileMEX,' VariablesGrid out_algstates; \n');
0048
0049 fprintf(cppobj.fileMEX,sprintf(' %s.getDifferentialStates(out_states);\n', obj.name));
0050 if (~isempty(cppobj.u))
0051 fprintf(cppobj.fileMEX,sprintf(' %s.getControls(out_controls);\n', obj.name));
0052 end
0053 if (~isempty(cppobj.p))
0054 fprintf(cppobj.fileMEX,sprintf(' %s.getParameters(out_parameters);\n', obj.name));
0055 end
0056 if (~isempty(cppobj.w))
0057 fprintf(cppobj.fileMEX,sprintf(' %s.getDisturbances(out_disturbances);\n', obj.name));
0058 end
0059 if (~isempty(cppobj.z))
0060 fprintf(cppobj.fileMEX,sprintf(' %s.getAlgebraicStates(out_algstates);\n', obj.name));
0061 end
0062
0063
0064 if (ACADO_.results_to_file == true)
0065
0066 fprintf(cppobj.fileMEX,sprintf(' out_states.printToFile( "%s_OUT_states.m","STATES",PS_MATLAB ); \n', cppobj.problemname));
0067 fprintf(cppobj.fileMEX,sprintf(' out_controls.printToFile( "%s_OUT_controls.m","CONTROLS",PS_MATLAB ); \n', cppobj.problemname));
0068 fprintf(cppobj.fileMEX,sprintf(' out_parameters.printToFile( "%s_OUT_parameters.m","PARAMETERS",PS_MATLAB ); \n', cppobj.problemname));
0069 fprintf(cppobj.fileMEX,sprintf(' out_disturbances.printToFile( "%s_OUT_disturbances.m","DISTURBANCES",PS_MATLAB ); \n', cppobj.problemname));
0070 fprintf(cppobj.fileMEX,sprintf(' out_algstates.printToFile( "%s_OUT_algebraicstates.m","ALGEBRAICSTATES",PS_MATLAB ); \n', cppobj.problemname));
0071 end
0072
0073
0074 fprintf(cppobj.fileMEX,' const char* outputFieldNames[] = {"STATES", "CONTROLS", "PARAMETERS", "DISTURBANCES", "ALGEBRAICSTATES", "CONVERGENCE_ACHIEVED"}; \n');
0075 fprintf(cppobj.fileMEX,' plhs[0] = mxCreateStructMatrix( 1,1,6,outputFieldNames ); \n');
0076
0077 cppobj.getCPPlefthandout('OutS', 'outS', 'out_states')
0078 fprintf(cppobj.fileMEX,' mxSetField( plhs[0],0,"STATES",OutS );\n');
0079
0080 cppobj.getCPPlefthandout('OutC', 'outC', 'out_controls')
0081 fprintf(cppobj.fileMEX,' mxSetField( plhs[0],0,"CONTROLS",OutC );\n');
0082
0083 cppobj.getCPPlefthandout('OutP', 'outP', 'out_parameters')
0084 fprintf(cppobj.fileMEX,' mxSetField( plhs[0],0,"PARAMETERS",OutP );\n');
0085
0086 cppobj.getCPPlefthandout('OutW', 'outW', 'out_disturbances')
0087 fprintf(cppobj.fileMEX,' mxSetField( plhs[0],0,"DISTURBANCES",OutW );\n');
0088
0089 cppobj.getCPPlefthandout('OutZ', 'outZ', 'out_algstates')
0090 fprintf(cppobj.fileMEX,' mxSetField( plhs[0],0,"ALGEBRAICSTATES",OutZ );\n');
0091
0092 fprintf(cppobj.fileMEX,' mxArray *OutConv = NULL;\n');
0093 fprintf(cppobj.fileMEX,' if ( returnvalue == SUCCESSFUL_RETURN ) { OutConv = mxCreateDoubleScalar( 1 ); }else{ OutConv = mxCreateDoubleScalar( 0 ); } \n');
0094 fprintf(cppobj.fileMEX,' mxSetField( plhs[0],0,"CONVERGENCE_ACHIEVED",OutConv );\n');
0095
0096 fprintf(cppobj.fileMEX,'\n');
0097 end
0098
0099 end