Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
Expand all | Collapse all

Implementating CPLEX in Matlab Simulink

  • 1.  Implementating CPLEX in Matlab Simulink

    Posted Wed February 01, 2012 09:04 PM

    Originally posted by: ranran_uw


    Hi,
    I am working on a project needs to implement cplex in Matlab simlink embedded function. However, matlab does not allow to generate c code for the cplex algorithm. Could you give me some suggestion on this problem?

    Thanks!
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Implementating CPLEX in Matlab Simulink

    Posted Thu February 02, 2012 12:47 AM

    Originally posted by: John Cui


    What do you mean about "implement cplex in MATLAB"? do you mean you want to use cplex in matlab?

    We do have CPLEX API for MATLAB if you are using CPLEX 12.x.

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Implementating CPLEX in Matlab Simulink

    Posted Thu February 02, 2012 01:04 AM

    Originally posted by: ranran_uw


    John,

    Thanks for your reply! I have a simulation run in Simulink enviroment, in the simulink model, i have a embedded Matlab function block where the cplex is called inside the block. It is not using Matlab .m file to call cplex. In order to run the embedded function in Simulink, it requires to generate C code first and cplex .p function called in simulink cannot generate C code .

    The reason i use simulink is because i need to test a hardware-in-loop using the optimization method solved by cplex. My question is if cplex can be implemented in simulink. If not, is there any suggestions? i am using academic version cplex 12.3.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Implementating CPLEX in Matlab Simulink

    Posted Thu February 02, 2012 01:07 AM

    Originally posted by: John Cui


    You are not using our MATLAB api, say cplexlp, cplexmilp, cplexqcp, or Cplex class in MATLAB, correct?
    But you are using CPLEX other APIs in your code?

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Implementating CPLEX in Matlab Simulink

    Posted Thu February 02, 2012 01:13 AM

    Originally posted by: ranran_uw


    Yes, i am using Matlab API, the one i am using is cplexlp
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Implementating CPLEX in Matlab Simulink

    Posted Thu February 02, 2012 01:18 AM

    Originally posted by: John Cui


    Ah, I understand now.

    Your matlab code called our cplexlp, and you want to generate C code from your matlab code, but failed because cplexlp. Right?

    I am not sure it is make sense for matlab mex dll, such as cplexlink123 in our matlab API. I suggest you post a question in MATHWORKS forum
    to ask about generate matlab code to C code, but the matlab code called a external mex file and p file.

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Implementating CPLEX in Matlab Simulink

    Posted Thu February 02, 2012 01:14 AM

    Originally posted by: ranran_uw


    the matlab api is called in simulink, not in matlab .m file
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Implementating CPLEX in Matlab Simulink

    Posted Thu February 02, 2012 01:19 AM

    Originally posted by: John Cui


    I didn't use simulink, so I can not reproduce this. Sorry.
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Implementating CPLEX in Matlab Simulink

    Posted Thu February 02, 2012 01:30 AM

    Originally posted by: ranran_uw


    Thanks! My last question is: the other APIs, i.e., C API, do they have the same function like cplexlp or cplexmilp?
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Implementating CPLEX in Matlab Simulink

    Posted Thu February 02, 2012 01:37 AM

    Originally posted by: John Cui


    Sure, our MATLAB api was based on our C API, CPXlpopt, CPXmipopt are the functions in C API to solve LP and MIP like cplexlp, cplexmilp.

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Implementating CPLEX in Matlab Simulink

    Posted Thu February 02, 2012 02:28 AM

    Originally posted by: SystemAdmin


    It might be an obvious thing to ask, but can't you just implement the C function yourself instead of having it generated?
    CPLEX has a C API and it should not be too hard to use that to setup and solve a model if you already have the data in matlab.
    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: Implementating CPLEX in Matlab Simulink

    Posted Thu February 02, 2012 02:37 AM

    Originally posted by: ranran_uw


    The hardware in loop i am using is dSPACE, I am not sure if you are familar with it or not. Their interface is developed in simulink and all of their modules are built as simlink blocks. The control variable i calculated using cplex is intended to be input for the dSPACE blocks. in other words, i use the varialbes generated by cplex to control the connected hardware. That's why i prefer to do everything in Simulink.
    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: Implementating CPLEX in Matlab Simulink

    Posted Tue February 27, 2018 03:57 PM

    Originally posted by: Faeza


    Hi,

     

    I am facing the same problem. I wanted to use cplex in a Matlab Simulink block function. It is not working. It is showing the error like:

    "P-file 'C:\Program Files\IBM\ILOG\CPLEX_Studio1271\cplex\matlab\x64_win64\cplexlp.p' is not authorized for compilation. To support compilation, please consider using 'coder.allowpcode' in this file. When the file defines a MATLAB class, 'coder.allowpcode' should be added to the class constructor."

     

    Can anyone help me?


    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  Re: Implementating CPLEX in Matlab Simulink

    Posted Tue June 18, 2019 01:30 PM

    Originally posted by: Laci Ladanyi


    The bad news is that this is not likely to happen. As far as we understand, if coder.allowpcode is used, then MATLAB's codegen can create a C/C++ file from the p-file, which would sort of defeat the purpose of shipping a p-file (which is an obfuscated m-file) to begin with...

    However, the blog page https://blogs.mathworks.com/simulink/2014/01/08/simulink-and-matlab-objects/ seems to imply that you can get around this restriction by using extrinsic functions. Note that I have never actually used this, I just stumbled across that blog when that blog was referenced for a problem exactly like yours involving the mqtt library (https://ww2.mathworks.cn/matlabcentral/answers/418697-mqtt-library-incompatible-with-simulink).

    Good luck!

     


    #CPLEXOptimizers
    #DecisionOptimization