MATLAB to GAMS and GAMS to MATLAB

Archive of Gamsworld Google Group
Archiver
User
User
Posts: 7876
Joined: 7 years ago

MATLAB to GAMS and GAMS to MATLAB

Post by Archiver »



Hi!

Can you help me in constructing interfaces between GAMS and MATLAB? I
have read the introduction http://www.cs.wisc.edu/math-prog/matlab.html
However it doesn't fix my problem.

My challenge is:
- MATLAB to GAMS
I have data for an optimisation problem generated by MATLAB and I want
to solve it by using GAMS.


- GAMS to MATLAB
The solution will be used in MATLAB for further calculation.

The attached gams-file is only a small clear extract of the total
optimisation model. The GAMS-Input (MATLAB => GAMS) is:
p_load(t)
and
the output of GAMS (GAMS => MATLAB) is P(i,t) (actual power output
of plant i in time t)


Thanks a lot for your help.

Regards,

David

The given GAMS-model:



SETS
i unit /1 * 4/



t consideration period /1*2/


;

Parameter

price_fuel(i) fuel price for gas (EUR per kWh)/1 0.0001
2 0.002
3
0.0025
4
0.0015/

* p_load(t) is MATLAB output and not determined in GAMS like now.
p_load(t) /1 50
2 100/


p_min(i) /1 15
2 15
3 12
4 12/

p_max(i) /1 40
2 45
3 50
4 50/


VARIABLES
C_total total costs of the schedule
;

POSITIVE VARIABLES
P actual power output of plant i in time t
P_fuel fuel rating of plant i in time t
P1 required power of unit i in t
;

BINARY VARIABLES
gamma_on
;
$ontext
P.up('1',t) = 40;
P.up('2',t) = 45;
P.up('3',t) = 50;
P.up('4',t) = 50;
P.lo('1',t) = 15;
P.lo('2',t) = 15;
P.lo('3',t) = 12;
P.lo('4',t) = 12;
$offtext
EQUATIONS
fuel simple linear fuel function
cost_total cost function
load_cover load cover constraint
syst_unit_pos1 Sytem unit constraint: lower boundfor
operational range
syst_unit_pos2 Sytem unit constraint: upper boundfor
operational range

;


*Load in the system constraint
load_cover(t)..
p_load(t) =E= sum(i, P1(i,t))
;

*Fuel function
fuel(i,t)..
P_fuel(i,t) =E= (2.5891 * P1(i,t) + 43.031)
;


*Object function
cost_total..
C_total =E= sum(t, ( sum(i,
price_fuel(i)* P_fuel(i,t)) ))*0.25
;
*Sytem unit constraint: lower bound for operational range
syst_unit_pos1(i,t)..
P1(i,t) =G= gamma_on(i,t) * p_min(i)
;
*Sytem unit constraint: upper bound for operational range
syst_unit_pos2(i,t)..
P1(i,t) =L= gamma_on(i,t) * p_max(i)
;



model schedule /all/;

solve schedule using mip minimizing C_total;

execute_unload "C:\tmp\resultout.gdx";


Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: MATLAB to GAMS and GAMS to MATLAB

Post by Archiver »


Hello David
Why don't you code everything in Gams?
If you don't want to code all in Gams, I think the best way to do such communication is to use a matlab-odbc export ( to send data from Matlab to Gams).
It could be performed this way:
1)Perform Matlab operations
2)Send Matlab using ODBC ( make a google search matlab odbc, you'll find some information )
3)Read this ODBC data into Gams
4)Run Gams
5)Export to Matlab using Gams (http://pages.cs.wisc.edu/~ferris/matlabgams.pdf)
There are some examples in ODBC data reading in Gams in Gams model libraries ( data utilities models)
Regards
Edson

David escreveu:
> Hi!
>
> Can you help me in constructing interfaces between GAMS and MATLAB? I
> have read the introduction http://www.cs.wisc.edu/math-prog/matlab.html
> However it doesn't fix my problem.
>
> My challenge is:
> - MATLAB to GAMS
> I have data for an optimisation problem generated by MATLAB and I want
> to solve it by using GAMS.
>
>
> - GAMS to MATLAB
> The solution will be used in MATLAB for further calculation.
>
> The attached gams-file is only a small clear extract of the total
> optimisation model. The GAMS-Input (MATLAB => GAMS) is:
> p_load(t)
> and
> the output of GAMS (GAMS => MATLAB) is P(i,t) (actual power output
> of plant i in time t)
>
>
> Thanks a lot for your help.
>
> Regards,
>
> David
>
> The given GAMS-model:
>
>
>
> SETS
> i unit /1 * 4/
>
>
>
> t consideration period /1*2/
>
>
> ;
>
> Parameter
>
> price_fuel(i) fuel price for gas (EUR per kWh)/1 0.0001
> 2 0.002
> 3
> 0.0025
> 4
> 0.0015/
>
> * p_load(t) is MATLAB output and not determined in GAMS like now.
> p_load(t) /1 50
> 2 100/
>
>
> p_min(i) /1 15
> 2 15
> 3 12
> 4 12/
>
> p_max(i) /1 40
> 2 45
> 3 50
> 4 50/
>
>
> VARIABLES
> C_total total costs of the schedule
> ;
>
> POSITIVE VARIABLES
> P actual power output of plant i in time t
> P_fuel fuel rating of plant i in time t
> P1 required power of unit i in t
> ;
>
> BINARY VARIABLES
> gamma_on
> ;
> $ontext
> P.up('1',t) = 40;
> P.up('2',t) = 45;
> P.up('3',t) = 50;
> P.up('4',t) = 50;
> P.lo('1',t) = 15;
> P.lo('2',t) = 15;
> P.lo('3',t) = 12;
> P.lo('4',t) = 12;
> $offtext
> EQUATIONS
> fuel simple linear fuel function
> cost_total cost function
> load_cover load cover constraint
> syst_unit_pos1 Sytem unit constraint: lower boundfor
> operational range
> syst_unit_pos2 Sytem unit constraint: upper boundfor
> operational range
>
> ;
>
>
> *Load in the system constraint
> load_cover(t)..
> p_load(t) =E= sum(i, P1(i,t))
> ;
>
> *Fuel function
> fuel(i,t)..
> P_fuel(i,t) =E= (2.5891 * P1(i,t) + 43.031)
> ;
>
>
> *Object function
> cost_total..
> C_total =E= sum(t, ( sum(i,
> price_fuel(i)* P_fuel(i,t)) ))*0.25
> ;
> *Sytem unit constraint: lower bound for operational range
> syst_unit_pos1(i,t)..
> P1(i,t) =G= gamma_on(i,t) * p_min(i)
> ;
> *Sytem unit constraint: upper bound for operational range
> syst_unit_pos2(i,t)..
> P1(i,t) =L= gamma_on(i,t) * p_max(i)
> ;
>
>
>
> model schedule /all/;
>
> solve schedule using mip minimizing C_total;
>
> execute_unload "C:\tmp\resultout.gdx";
>
>

--
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.


Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: MATLAB to GAMS and GAMS to MATLAB

Post by Archiver »


Hi Davis,

With regard to your question I suggest you to follow these steps:

*a) Installation:
First of all, you need to install both MATLAB and GAMS on your machine.
We will assume that the relevant system (installation) directories are:

C:\MATLAB and C:\GAMS

1. Copy matout.gms in C:\GAMS\inclib\matout.gms
2. Copy gams.dll in C:\MATLAB\toolbox\local\gams.dll
3. Set the environment variable path of GAMS

To test the installation, carry out the following steps:
1. Start up MATLAB
2. In the MATLAB command window, change directories to the examples directory provided as part of the distribution (This directory contains at least two files, testinst.m and testinst.gms that are required for this test.)
3. Run the example “testinst” that is found in the examples directory of the distribution.

At the MATLAB prompt you just type:
>>testinst

The resulting output will depend on the platform on which you run this from.

*b) Returning Values to MATLAB:
In order to run the same model within MATLAB and return the solution vector
variable of x(i) and parameter of d(i, j) back into the MATLAB workspace, one
change is required to the GAMS file, namely to add the below line after the
SOLVE statement:

$libinclude matout x.l i
$libinclude matout d i j

This just writes out the level values of the solution to a file that can be read back
into MATLAB. In MATLAB, you just execute the following statement:

[x d] = gams('NameGamsFile');

For more information click here:
http://pms.pwut.ir/(S(dvgjaanzx4nzjci5wbdvvznz))/Download.aspx

or

my weblog: http://mortezash.blogfa.com/ (in Persian)

Morteza Sha'ban-Zadeh








--- On Sat, 12/18/10, David wrote:


From: David
Subject: MATLAB to GAMS and GAMS to MATLAB
To: "gamsworld"
Date: Saturday, December 18, 2010, 6:13 AM


Hi!

Can you help me in constructing interfaces between GAMS and MATLAB? I
have read the introduction http://www.cs.wisc.edu/math-prog/matlab.html
However it doesn't fix my problem.

My challenge is:
- MATLAB to GAMS
I have data for an optimisation problem generated by MATLAB and I want
to solve it by using GAMS.


- GAMS to MATLAB
The solution will be used in MATLAB for further calculation.

The attached gams-file is only a small clear extract of the total
optimisation model. The GAMS-Input (MATLAB => GAMS) is:
p_load(t)
and
the output of GAMS (GAMS => MATLAB) is P(i,t) (actual power output
of plant i in time t)


Thanks a lot for your help.

Regards,

David

The given GAMS-model:



SETS
i unit /1 * 4/



t consideration period /1*2/


;

Parameter

price_fuel(i) fuel price for gas (EUR per kWh)/1 0.0001
2 0.002
3
0.0025
4
0.0015/

* p_load(t) is MATLAB output and not determined in GAMS like now.
p_load(t) /1 50
2 100/


p_min(i) /1 15
2 15
3 12
4 12/

p_max(i) /1 40
2 45
3 50
4 50/


VARIABLES
C_total total costs of the schedule
;

POSITIVE VARIABLES
P actual power output of plant i in time t
P_fuel fuel rating of plant i in time t
P1 required power of unit i in t
;

BINARY VARIABLES
gamma_on
;
$ontext
P.up('1',t) = 40;
P.up('2',t) = 45;
P.up('3',t) = 50;
P.up('4',t) = 50;
P.lo('1',t) = 15;
P.lo('2',t) = 15;
P.lo('3',t) = 12;
P.lo('4',t) = 12;
$offtext
EQUATIONS
fuel simple linear fuel function
cost_total cost function
load_cover load cover constraint
syst_unit_pos1 Sytem unit constraint: lower boundfor
operational range
syst_unit_pos2 Sytem unit constraint: upper boundfor
operational range

;


*Load in the system constraint
load_cover(t)..
p_load(t) =E= sum(i, P1(i,t))
;

*Fuel function
fuel(i,t)..
P_fuel(i,t) =E= (2.5891 * P1(i,t) + 43.031)
;


*Object function
cost_total..
C_total =E= sum(t, ( sum(i,
price_fuel(i)* P_fuel(i,t)) ))*0.25
;
*Sytem unit constraint: lower bound for operational range
syst_unit_pos1(i,t)..
P1(i,t) =G= gamma_on(i,t) * p_min(i)
;
*Sytem unit constraint: upper bound for operational range
syst_unit_pos2(i,t)..
P1(i,t) =L= gamma_on(i,t) * p_max(i)
;



model schedule /all/;

solve schedule using mip minimizing C_total;

execute_unload "C:\tmp\resultout.gdx";

--
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.


--
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: MATLAB to GAMS and GAMS to MATLAB

Post by Archiver »


Hi Morteza Sha'ban-Zadeh, Hi Edson,

Thank you for your help. I will try both ways.

Regrads,

David


Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: MATLAB to GAMS and GAMS to MATLAB

Post by Archiver »

David,

This question and ones like it seem to be common ones. I collected
some thoughts on this, along with a fully-worked-out example
illustrating my suggested approach, and made this available as a FAQ
at http://www.gams.com/~steve/gdxmrw.html. HTH,

-Steve

On Sat, Dec 18, 2010 at 6:13 AM, David wrote:
> >
> > Hi!
> >
> > Can you help me in constructing interfaces between GAMS and MATLAB? I
> > have read the introduction http://www.cs.wisc.edu/math-prog/matlab.html
> > However it doesn't fix my problem.
> >
> > My challenge is:
> > - MATLAB to GAMS
> > I have data for an optimisation problem generated by MATLAB and I want
> > to solve it by using GAMS.
> >
> >
> > - GAMS to MATLAB
> > The solution will be used in MATLAB for further calculation.
> >
> > The attached gams-file is only a small clear extract of the total
> > optimisation model. The GAMS-Input (MATLAB => GAMS) is:
> > p_load(t)
> > and
> > the output of GAMS (GAMS => MATLAB) is P(i,t) (actual power output
> > of plant i in time t)
> >
> >
> > Thanks a lot for your help.
> >
> > Regards,
> >
> > David
> >
> > The given GAMS-model:
> >
> >
> >
> > SETS
> > i unit /1 * 4/
> >
> >
> >
> > t consideration period /1*2/
> >
> >
> > ;
> >
> > Parameter
> >
> > price_fuel(i) fuel price for gas (EUR per kWh)/1 0.0001
> > 2 0.002
> > 3
> > 0.0025
> > 4
> > 0.0015/
> >
> > * p_load(t) is MATLAB output and not determined in GAMS like now.
> > p_load(t) /1 50
> > 2 100/
> >
> >
> > p_min(i) /1 15
> > 2 15
> > 3 12
> > 4 12/
> >
> > p_max(i) /1 40
> > 2 45
> > 3 50
> > 4 50/
> >
> >
> > VARIABLES
> > C_total total costs of the schedule
> > ;
> >
> > POSITIVE VARIABLES
> > P actual power output of plant i in time t
> > P_fuel fuel rating of plant i in time t
> > P1 required power of unit i in t
> > ;
> >
> > BINARY VARIABLES
> > gamma_on
> > ;
> > $ontext
> > P.up('1',t) = 40;
> > P.up('2',t) = 45;
> > P.up('3',t) = 50;
> > P.up('4',t) = 50;
> > P.lo('1',t) = 15;
> > P.lo('2',t) = 15;
> > P.lo('3',t) = 12;
> > P.lo('4',t) = 12;
> > $offtext
> > EQUATIONS
> > fuel simple linear fuel function
> > cost_total cost function
> > load_cover load cover constraint
> > syst_unit_pos1 Sytem unit constraint: lower boundfor
> > operational range
> > syst_unit_pos2 Sytem unit constraint: upper boundfor
> > operational range
> >
> > ;
> >
> >
> > *Load in the system constraint
> > load_cover(t)..
> > p_load(t) =E= sum(i, P1(i,t))
> > ;
> >
> > *Fuel function
> > fuel(i,t)..
> > P_fuel(i,t) =E= (2.5891 * P1(i,t) + 43.031)
> > ;
> >
> >
> > *Object function
> > cost_total..
> > C_total =E= sum(t, ( sum(i,
> > price_fuel(i)* P_fuel(i,t)) ))*0.25
> > ;
> > *Sytem unit constraint: lower bound for operational range
> > syst_unit_pos1(i,t)..
> > P1(i,t) =G= gamma_on(i,t) * p_min(i)
> > ;
> > *Sytem unit constraint: upper bound for operational range
> > syst_unit_pos2(i,t)..
> > P1(i,t) =L= gamma_on(i,t) * p_max(i)
> > ;
> >
> >
> >
> > model schedule /all/;
> >
> > solve schedule using mip minimizing C_total;
> >
> > execute_unload "C:\tmp\resultout.gdx";
> >
> > --
> > To post to this group, send email to gamsworld@googlegroups.com.
> > To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
> > For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.
> >
> >



-- Steven Dirkse, Ph.D. GAMS Development Corp., Washington DC Voice: (202)342-0180 Fax: (202)342-0181 sdirkse@gams.com http://www.gams.com

Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: MATLAB to GAMS and GAMS to MATLAB

Post by Archiver »

Morteza,

The notes you provided below are for an older version of the GAMS/Matlab interface tools. In the newest version all of the tools are contained in the GAMS distribution, so there is no need to copy files like matout.gms and gams.dll. Also, the gams.dll file is a very old Mex-file. Matlab has been using platform-specific names for their Mex-files for several years and the new interface follows this standard. I encourage all user to update to the latest version of these tools found in the recent GAMS Distribution 23.6.2.

-Steve

On Mon, Dec 20, 2010 at 5:42 AM, .::Morteza Shabanzadeh::. wrote:

Hi Davis,

With regard to your question I suggest you to follow these steps:

*a) Installation:
First of all, you need to install both MATLAB and GAMS on your machine.
We will assume that the relevant system (installation) directories are:

C:\MATLAB and C:\GAMS

1. Copy matout.gms in C:\GAMS\inclib\matout.gms
2. Copy gams.dll in C:\MATLAB\toolbox\local\gams.dll
3. Set the environment variable path of GAMS

To test the installation, carry out the following steps:
1. Start up MATLAB
2. In the MATLAB command window, change directories to the examples directory provided as part of the distribution (This directory contains at least two files, testinst.m and testinst.gms that are required for this test.)
3. Run the example “testinst” that is found in the examples directory of the distribution.

At the MATLAB prompt you just type:
>>testinst

The resulting output will depend on the platform on which you run this from.

*b) Returning Values to MATLAB:
In order to run the same model within MATLAB and return the solution vector
variable of x(i) and parameter of d(i, j) back into the MATLAB workspace, one
change is required to the GAMS file, namely to add the below line after the
SOLVE statement:

$libinclude matout x.l i
$libinclude matout d i j

This just writes out the level values of the solution to a file that can be read back
into MATLAB. In MATLAB, you just execute the following statement:

[x d] = gams('NameGamsFile');

For more information click here:
http://pms.pwut.ir/(S(dvgjaanzx4nzjci5wbdvvznz))/Download.aspx

or

my weblog: http://mortezash.blogfa.com/ (in Persian)

Morteza Sha'ban-Zadeh








--- On Sat, 12/18/10, David wrote:


From: David
Subject: MATLAB to GAMS and GAMS to MATLAB
To: "gamsworld"
Date: Saturday, December 18, 2010, 6:13 AM



Hi!

Can you help me in constructing interfaces between GAMS and MATLAB? I
have read the introduction http://www.cs.wisc.edu/math-prog/matlab.html
However it doesn't fix my problem.

My challenge is:
- MATLAB to GAMS
I have data for an optimisation problem generated by MATLAB and I want
to solve it by using GAMS.


- GAMS to MATLAB
The solution will be used in MATLAB for further calculation.

The attached gams-file is only a small clear extract of the total
optimisation model. The GAMS-Input (MATLAB => GAMS) is:
p_load(t)
and
the output of GAMS (GAMS => MATLAB) is P(i,t) (actual power output
of plant i in time t)


Thanks a lot for your help.

Regards,

David

The given GAMS-model:



SETS
i unit /1 * 4/



t consideration period /1*2/


;

Parameter

price_fuel(i) fuel price for gas (EUR per kWh)/1 0.0001
2 0.002
3
0.0025
4
0.0015/

* p_load(t) is MATLAB output and not determined in GAMS like now.
p_load(t) /1 50
2 100/


p_min(i) /1 15
2 15
3 12
4 12/

p_max(i) /1 40
2 45
3 50
4 50/


VARIABLES
C_total total costs of the schedule
;

POSITIVE VARIABLES
P actual power output of plant i in time t
P_fuel fuel rating of plant i in time t
P1 required power of unit i in t
;

BINARY VARIABLES
gamma_on
;
$ontext
P.up('1',t) = 40;
P.up('2',t) = 45;
P.up('3',t) = 50;
P.up('4',t) = 50;
P.lo('1',t) = 15;
P.lo('2',t) = 15;
P.lo('3',t) = 12;
P.lo('4',t) = 12;
$offtext
EQUATIONS
fuel simple linear fuel function
cost_total cost function
load_cover load cover constraint
syst_unit_pos1 Sytem unit constraint: lower boundfor
operational range
syst_unit_pos2 Sytem unit constraint: upper boundfor
operational range

;


*Load in the system constraint
load_cover(t)..
p_load(t) =E= sum(i, P1(i,t))
;

*Fuel function
fuel(i,t)..
P_fuel(i,t) =E= (2.5891 * P1(i,t) + 43.031)
;


*Object function
cost_total..
C_total =E= sum(t, ( sum(i,
price_fuel(i)* P_fuel(i,t)) ))*0.25
;
*Sytem unit constraint: lower bound for operational range
syst_unit_pos1(i,t)..
P1(i,t) =G= gamma_on(i,t) * p_min(i)
;
*Sytem unit constraint: upper bound for operational range
syst_unit_pos2(i,t)..
P1(i,t) =L= gamma_on(i,t) * p_max(i)
;



model schedule /all/;

solve schedule using mip minimizing C_total;

execute_unload "C:\tmp\resultout.gdx";

--
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.


--
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.




--
Steven Dirkse, Ph.D.
GAMS Development Corp., Washington DC
Voice: (202)342-0180 Fax: (202)342-0181
sdirkse@gams.com
http://www.gams.com
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: MATLAB to GAMS and GAMS to MATLAB

Post by Archiver »


Dear Steve,

You right. I used an older version of the GAMS/MATLAB interface tools but absolutely I will update it.

Thanks,







--- On Tue, 12/21/10, Steven Dirkse wrote:


From: Steven Dirkse
Subject: Re: MATLAB to GAMS and GAMS to MATLAB
To: gamsworld@googlegroups.com
Date: Tuesday, December 21, 2010, 9:40 AM

Morteza,

The notes you provided below are for an older version of the GAMS/Matlab interface tools. In the newest version all of the tools are contained in the GAMS distribution, so there is no need to copy files like matout.gms and gams.dll. Also, the gams.dll file is a very old Mex-file. Matlab has been using platform-specific names for their Mex-files for several years and the new interface follows this standard. I encourage all user to update to the latest version of these tools found in the recent GAMS Distribution 23.6.2.

-Steve

On Mon, Dec 20, 2010 at 5:42 AM, .::Morteza Shabanzadeh::. wrote:

Hi Davis,

With regard to your question I suggest you to follow these steps:

*a) Installation:
First of all, you need to install both MATLAB and GAMS on your machine.
We will assume that the relevant system (installation) directories are:

C:\MATLAB and C:\GAMS

1. Copy matout.gms in C:\GAMS\inclib\matout.gms
2. Copy gams.dll in C:\MATLAB\toolbox\local\gams.dll
3. Set the environment variable path of GAMS

To test the installation, carry out the following steps:
1. Start up MATLAB
2. In the MATLAB command window, change directories to the examples directory provided as part of the distribution (This directory contains at least two files, testinst.m and testinst.gms that are required for this test.)
3. Run the example “testinst” that is found in the examples directory of the distribution.

At the MATLAB prompt you just type:
>>testinst

The resulting output will depend on the platform on which you run this from.

*b) Returning Values to MATLAB:
In order to run the same model within MATLAB and return the solution vector
variable of x(i) and parameter of d(i, j) back into the MATLAB workspace, one
change is required to the GAMS file, namely to add the below line after the
SOLVE statement:

$libinclude matout x.l i
$libinclude matout d i j

This just writes out the level values of the solution to a file that can be read back
into MATLAB. In MATLAB, you just execute the following statement:

[x d] = gams('NameGamsFile');

For more information click here:
http://pms.pwut.ir/(S(dvgjaanzx4nzjci5wbdvvznz))/Download.aspx

or

my weblog: http://mortezash.blogfa.com/ (in Persian)

Morteza Sha'ban-Zadeh








--- On Sat, 12/18/10, David wrote:


From: David
Subject: MATLAB to GAMS and GAMS to MATLAB
To: "gamsworld"
Date: Saturday, December 18, 2010, 6:13 AM



Hi!

Can you help me in constructing interfaces between GAMS and MATLAB? I
have read the introduction http://www.cs.wisc.edu/math-prog/matlab.html
However it doesn't fix my problem.

My challenge is:
- MATLAB to GAMS
I have data for an optimisation problem generated by MATLAB and I want
to solve it by using GAMS.


- GAMS to MATLAB
The solution will be used in MATLAB for further calculation.

The attached gams-file is only a small clear extract of the total
optimisation model. The GAMS-Input (MATLAB => GAMS) is:
p_load(t)
and
the output of GAMS (GAMS => MATLAB) is P(i,t) (actual power output
of plant i in time t)


Thanks a lot for your help.

Regards,

David

The given GAMS-model:



SETS
i unit /1 * 4/



t consideration period /1*2/


;

Parameter

price_fuel(i) fuel price for gas (EUR per kWh)/1 0.0001
2 0.002
3
0.0025
4
0.0015/

* p_load(t) is MATLAB output and not determined in GAMS like now.
p_load(t) /1 50
2 100/


p_min(i) /1 15
2 15
3 12
4 12/

p_max(i) /1 40
2 45
3 50
4 50/


VARIABLES
C_total total costs of the schedule
;

POSITIVE VARIABLES
P actual power output of plant i in time t
P_fuel fuel rating of plant i in time t
P1 required power of unit i in t
;

BINARY VARIABLES
gamma_on
;
$ontext
P.up('1',t) = 40;
P.up('2',t) = 45;
P.up('3',t) = 50;
P.up('4',t) = 50;
P.lo('1',t) = 15;
P.lo('2',t) = 15;
P.lo('3',t) = 12;
P.lo('4',t) = 12;
$offtext
EQUATIONS
fuel simple linear fuel function
cost_total cost function
load_cover load cover constraint
syst_unit_pos1 Sytem unit constraint: lower boundfor
operational range
syst_unit_pos2 Sytem unit constraint: upper boundfor
operational range

;


*Load in the system constraint
load_cover(t)..
p_load(t) =E= sum(i, P1(i,t))
;

*Fuel function
fuel(i,t)..
P_fuel(i,t) =E= (2.5891 * P1(i,t) + 43.031)
;


*Object function
cost_total..
C_total =E= sum(t, ( sum(i,
price_fuel(i)* P_fuel(i,t)) ))*0.25
;
*Sytem unit constraint: lower bound for operational range
syst_unit_pos1(i,t)..
P1(i,t) =G= gamma_on(i,t) * p_min(i)
;
*Sytem unit constraint: upper bound for operational range
syst_unit_pos2(i,t)..
P1(i,t) =L= gamma_on(i,t) * p_max(i)
;



model schedule /all/;

solve schedule using mip minimizing C_total;

execute_unload "C:\tmp\resultout.gdx";

--
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.


--
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.




--
Steven Dirkse, Ph.D.
GAMS Development Corp., Washington DC
Voice: (202)342-0180 Fax: (202)342-0181
sdirkse@gams.com
http://www.gams.com
--
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.


--
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: MATLAB to GAMS and GAMS to MATLAB

Post by Archiver »


Hi Steve,

Your approach works perfectly translated to my problem.
Thank you for help.

Regards,

David

On 21 Dez. 2010, 15:36, Steven Dirkse wrote:
> > David,
> >
> > This question and ones like it seem to be common ones. I collected
> > some thoughts on this, along with a fully-worked-out example
> > illustrating my suggested approach, and made this available as a FAQ
> > athttp://www.gams.com/~steve/gdxmrw.html. HTH,
> >
> > -Steve
> >
> >
> >
> >
> >
> > On Sat, Dec 18, 2010 at 6:13 AM, David wrote:
> >
>> > > Hi!
> >
>> > > Can you help me in constructing interfaces between GAMS and MATLAB? I
>> > > have read the introductionhttp://www.cs.wisc.edu/math-prog/matlab.html
>> > > However it doesn't fix my problem.
> >
>> > > My challenge is:
>> > > - MATLAB to GAMS
>> > > I have data for an optimisation problem generated by MATLAB and I want
>> > > to solve it by using GAMS.
> >
>> > > - GAMS to MATLAB
>> > > The solution will be used in MATLAB for further calculation.
> >
>> > > The attached gams-file is only a small clear extract of the total
>> > > optimisation model. The GAMS-Input (MATLAB => GAMS) is:
>> > > p_load(t)
>> > > and
>> > > the output of GAMS (GAMS => MATLAB) is P(i,t) (actual power output
>> > > of plant i in time t)
> >
>> > > Thanks a lot for your help.
> >
>> > > Regards,
> >
>> > > David
> >
>> > > The given GAMS-model:
> >
>> > > SETS
>> > > i unit /1 * 4/
> >
>> > > t consideration period /1*2/
> >
>> > > ;
> >
>> > > Parameter
> >
>> > > price_fuel(i) fuel price for gas (EUR per kWh)/1 0.0001
>> > > 2 0.002
>> > > 3
>> > > 0.0025
>> > > 4
>> > > 0.0015/
> >
>> > > * p_load(t) is MATLAB output and not determined in GAMS like now.
>> > > p_load(t) /1 50
>> > > 2 100/
> >
>> > > p_min(i) /1 15
>> > > 2 15
>> > > 3 12
>> > > 4 12/
> >
>> > > p_max(i) /1 40
>> > > 2 45
>> > > 3 50
>> > > 4 50/
> >
>> > > VARIABLES
>> > > C_total total costs of the schedule
>> > > ;
> >
>> > > POSITIVE VARIABLES
>> > > P actual power output of plant i in time t
>> > > P_fuel fuel rating of plant i in time t
>> > > P1 required power of unit i in t
>> > > ;
> >
>> > > BINARY VARIABLES
>> > > gamma_on
>> > > ;
>> > > $ontext
>> > > P.up('1',t) = 40;
>> > > P.up('2',t) = 45;
>> > > P.up('3',t) = 50;
>> > > P.up('4',t) = 50;
>> > > P.lo('1',t) = 15;
>> > > P.lo('2',t) = 15;
>> > > P.lo('3',t) = 12;
>> > > P.lo('4',t) = 12;
>> > > $offtext
>> > > EQUATIONS
>> > > fuel simple linear fuel function
>> > > cost_total cost function
>> > > load_cover load cover constraint
>> > > syst_unit_pos1 Sytem unit constraint: lower boundfor
>> > > operational range
>> > > syst_unit_pos2 Sytem unit constraint: upper boundfor
>> > > operational range
> >
>> > > ;
> >
>> > > *Load in the system constraint
>> > > load_cover(t)..
>> > > p_load(t) =E= sum(i, P1(i,t))
>> > > ;
> >
>> > > *Fuel function
>> > > fuel(i,t)..
>> > > P_fuel(i,t) =E= (2.5891 * P1(i,t) + 43.031)
>> > > ;
> >
>> > > *Object function
>> > > cost_total..
>> > > C_total =E= sum(t, ( sum(i,
>> > > price_fuel(i)* P_fuel(i,t)) ))*0.25
>> > > ;
>> > > *Sytem unit constraint: lower bound for operational range
>> > > syst_unit_pos1(i,t)..
>> > > P1(i,t) =G= gamma_on(i,t) * p_min(i)
>> > > ;
>> > > *Sytem unit constraint: upper bound for operational range
>> > > syst_unit_pos2(i,t)..
>> > > P1(i,t) =L= gamma_on(i,t) * p_max(i)
>> > > ;
> >
>> > > model schedule /all/;
> >
>> > > solve schedule using mip minimizing C_total;
> >
>> > > execute_unload "C:\tmp\resultout.gdx";
> >
>> > > --
>> > > To post to this group, send email to gamsworld@googlegroups.com.
>> > > To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
>> > > For more options, visit this group athttp://groups.google.com/group/gamsworld?hl=en.
> >
> > --
> > Steven Dirkse, Ph.D.
> > GAMS Development Corp., Washington DC
> > Voice: (202)342-0180 Fax: (202)342-0181
> > sdir...@gams.comhttp://www.gams.com- Zitierten Text ausblenden -
> >
> > - Zitierten Text anzeigen -


Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: MATLAB to GAMS and GAMS to MATLAB

Post by Archiver »


Hello everyone!

I am trying to link Matlab and Gams.
The output of Gams model, which is named 'producer1',is the variable "y" which is a 17x104 matrix.
I type this line in command window:
y = gams('producer1')
It solves thd model but it cant assign the outputs to 'y' and returns this error:
"Number of output argument in Matlab exceed output argument specified in gams"
When I just type this line in command window:
gams('producer1')
the error doesn't appear any more.
Do you happen to help me?
Kind Regards

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: MATLAB to GAMS and GAMS to MATLAB

Post by Archiver »

Reply-to: gamsworld@googlegroups.com

Hello everyone!

I am trying to link Matlab and Gams
please send me a Simple example for better understanding.

Thank you.

On Saturday, December 18, 2010 2:43:48 PM UTC+3:30, David wrote:


Hi!

Can you help me in constructing interfaces between GAMS and MATLAB? I
have read the introduction http://www.cs.wisc.edu/math-prog/matlab.html
However it doesn't fix my problem.

My challenge is:
- MATLAB to GAMS
I have data for an optimisation problem generated by MATLAB and I want
to solve it by using GAMS.


- GAMS to MATLAB
The solution will be used in MATLAB for further calculation.

The attached gams-file is only a small clear extract of the total
optimisation model. The GAMS-Input (MATLAB => GAMS) is:
p_load(t)
and
the output of GAMS (GAMS => MATLAB) is P(i,t) (actual power output
of plant i in time t)


Thanks a lot for your help.

Regards,

David

The given GAMS-model:



SETS
i unit /1 * 4/



t consideration period /1*2/


;

Parameter

price_fuel(i) fuel price for gas (EUR per kWh)/1 0.0001
2 0.002
3
0.0025
4
0.0015/

* p_load(t) is MATLAB output and not determined in GAMS like now.
p_load(t) /1 50
2 100/


p_min(i) /1 15
2 15
3 12
4 12/

p_max(i) /1 40
2 45
3 50
4 50/


VARIABLES
C_total total costs of the schedule
;

POSITIVE VARIABLES
P actual power output of plant i in time t
P_fuel fuel rating of plant i in time t
P1 required power of unit i in t
;

BINARY VARIABLES
gamma_on
;
$ontext
P.up('1',t) = 40;
P.up('2',t) = 45;
P.up('3',t) = 50;
P.up('4',t) = 50;
P.lo('1',t) = 15;
P.lo('2',t) = 15;
P.lo('3',t) = 12;
P.lo('4',t) = 12;
$offtext
EQUATIONS
fuel simple linear fuel function
cost_total cost function
load_cover load cover constraint
syst_unit_pos1 Sytem unit constraint: lower boundfor
operational range
syst_unit_pos2 Sytem unit constraint: upper boundfor
operational range

;


*Load in the system constraint
load_cover(t)..
p_load(t) =E= sum(i, P1(i,t))
;

*Fuel function
fuel(i,t)..
P_fuel(i,t) =E= (2.5891 * P1(i,t) + 43.031)
;


*Object function
cost_total..
C_total =E= sum(t, ( sum(i,
price_fuel(i)* P_fuel(i,t)) ))*0.25
;
*Sytem unit constraint: lower bound for operational range
syst_unit_pos1(i,t)..
P1(i,t) =G= gamma_on(i,t) * p_min(i)
;
*Sytem unit constraint: upper bound for operational range
syst_unit_pos2(i,t)..
P1(i,t) =L= gamma_on(i,t) * p_max(i)
;



model schedule /all/;

solve schedule using mip minimizing C_total;

execute_unload "C:\tmp\resultout.gdx";

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Post Reply