Hi,
I want to define a constraint like this:
x1 + callfun(x2) =E= 1;
callfun(x2) is a function exists in MATLAB directory.
Is it possible to call it from GAMS?
if no, MATLAB code can be converted to C# (dll) and then the dll can be used as an external function?
Thank you
call external function
Re: call external function
GAMS can work with a DLL (but this needs to provide a special function API). See external equations (https://www.gams.com/24.9/docs/UG_Exter ... tions.html) or extrinsic functions (https://www.gams.com/24.9/docs/UG_Extri ... tions.html). Key is that you have to provide the derivative for this function to use it in a solver.
Hope this helps,
-Michael
Hope this helps,
-Michael
-
- User
- Posts: 8
- Joined: 6 years ago
Re: call external function
Michael,
The function - callfun(x2) - get x2 and then return an int value. It has no derivation. I tried to make dll in c# like this
Public static int callfun(int x_in)
{
x_in = x_in + 1
Return x_in
}
When I imported it through $Funlibin, I encountered a problem regarding loading error.
In guidelines written different programming languages are compatible, becoz I used c#,
May I have your comments?
The function - callfun(x2) - get x2 and then return an int value. It has no derivation. I tried to make dll in c# like this
Public static int callfun(int x_in)
{
x_in = x_in + 1
Return x_in
}
When I imported it through $Funlibin, I encountered a problem regarding loading error.
In guidelines written different programming languages are compatible, becoz I used c#,
May I have your comments?
-
- User
- Posts: 8
- Joined: 6 years ago
Re: call external function
$FuncLibIn gams_fun mylib/gamsfun
the dll file is "gamsfun.dll"
and the error is:
Problem occured when trying to load mylib/gamsfun64.ll
I don't know why 64 is added at the end!
the dll file is "gamsfun.dll"
and the error is:
Problem occured when trying to load mylib/gamsfun64.ll
I don't know why 64 is added at the end!
bussieck wrote:GAMS can work with a DLL (but this needs to provide a special function API). See external equations (https://www.gams.com/24.9/docs/UG_Exter ... tions.html) or extrinsic functions (https://www.gams.com/24.9/docs/UG_Extri ... tions.html). Key is that you have to provide the derivative for this function to use it in a solver.
Hope this helps,
-Michael
-
- User
- Posts: 8
- Joined: 6 years ago
Re: call external function
When I changed the code:
$FuncLibIn gams_fun mylib\gamsfun
I got this:
Entry not found: QueryLibrary in mylib\gamsfun.dll
again the file is not loaded properly.
$FuncLibIn gams_fun mylib\gamsfun
I got this:
Entry not found: QueryLibrary in mylib\gamsfun.dll
again the file is not loaded properly.
bussieck wrote:GAMS can work with a DLL (but this needs to provide a special function API). See external equations (https://www.gams.com/24.9/docs/UG_Exter ... tions.html) or extrinsic functions (https://www.gams.com/24.9/docs/UG_Extri ... tions.html). Key is that you have to provide the derivative for this function to use it in a solver.
Hope this helps,
-Michael
Re: call external function
Not sure I can be of any help if the examples and the documents are not sufficient. You can't just put a function in a DLL and hope GAMS works with it, You have to follow a strict API to make the function visible to GAMS. The trilib examples (https://www.gams.com/24.9/testlib_ml/li ... lib01.html) show this for a couple of languages with very simple function (sin/cos), so you can concentrate on the mechanics.
Good luck.
Michael
Good luck.
Michael
-
- User
- Posts: 8
- Joined: 6 years ago
Re: call external function
thank you, Micheal, for your time.
I saw the code and even your codes. I should confess GAMS is the most complicated programming languages I have ever seen! Unfortunately, it's like decoding... even the guides don't provide any clear explanation. I don't know why.
When I google GAMS tutorial or sources, nothing's found. It's really bizarre such a great software ...
anyway, Many thanks...
I saw the code and even your codes. I should confess GAMS is the most complicated programming languages I have ever seen! Unfortunately, it's like decoding... even the guides don't provide any clear explanation. I don't know why.
When I google GAMS tutorial or sources, nothing's found. It's really bizarre such a great software ...
anyway, Many thanks...
bussieck wrote:Not sure I can be of any help if the examples and the documents are not sufficient. You can't just put a function in a DLL and hope GAMS works with it, You have to follow a strict API to make the function visible to GAMS. The trilib examples (https://www.gams.com/24.9/testlib_ml/li ... lib01.html) show this for a couple of languages with very simple function (sin/cos), so you can concentrate on the mechanics.
Good luck.
Michael