Page 1 of 1

Creating a Subset

Posted: Sun Apr 19, 2020 1:06 pm
by Essouaied Aziz
Hello everybody ;

I'am here as a students who is using GAMS for university.

I already created this Set:

ConsT(j) Consommation avec le Total
/ GTunis
NE
NO
CO
CE
SO
SE
Total /

My goal is to creat a Subset of ConsT, called Cons, that includes all the colums of ConsT, except the column "Total", using those tricks of Yes and No

Can anyone help me with a suggestion of the code for that Subset ?

Thanks very much

Re: Creating a Subset

Posted: Sun Apr 19, 2020 4:35 pm
by Renger
Hi

Here is how I would do i:

Code: Select all

Cons(j) Consumption goods;

Cons(j)$ConsT(j) = YES;
Cons("Total")   = NO;
Cheers
Renger

Re: Creating a Subset

Posted: Sun Apr 19, 2020 6:37 pm
by Essouaied Aziz
Thanks for your help :D :D

Getting rid of scientific notation in Excel output

Posted: Mon May 11, 2020 4:28 pm
by Essouaied Aziz
Hello there ;
I have this code of Minimizing the cross-entropy

$TITLE Régionalisation de la composante Exportations

Set j Régions
/ GTunis
NE
NO
CO
CE
SO
SE
Total /

ExpoT(j) Exportations avec le Total
/ GTunis
NE
NO
CO
CE
SO
SE
Total /

Expo(j) Exportations sans le Total
/ GTunis
NE
NO
CO
CE
SO
SE /

i Moteurs de croissance
/ Expo /

Moteur(i)
/ Expo /

Alias(Expo,ExpoJ) ;
Alias(Moteur,MoteurJ) ;

PARAMETER
DONNEES(I,J) Matrice des donnees du probleme
SOLUTION(I,J) Solution
DISTRO(I,J) Matrice de la DISTRibution a priori (non ajustee) par région I et par exportation J
EPSILON Empeche des divisions par zero ;

Table Donnees(i,j)
GTunis NE NO CO CE SO SE Total
Expo 13927071831.970 5608646814.400 487841138.510 236404567.900 6482932150.210 461013044.130 369749658.720 34411800000.000 ;

DISTRO(I,J) = DONNEES(I,J)/100000 ;

DISTRO("Expo",Expo) $ (SUM(ExpoJ,DISTRO("Expo",ExpoJ)) NE 0)
= DISTRO("Expo",Expo)*SUM(Moteur,DISTRO(Moteur,"Total"))
/SUM(ExpoJ,DISTRO("Expo",ExpoJ)) ;

DISTRO("Expo",Expo) $ (SUM(ExpoJ,DISTRO("Expo",ExpoJ)) EQ 0) = 0 ;

Display DISTRO ;

EPSILON=0.0000000000000000000001 ;

VARIABLE
ZED(Moteur,Expo) Matrice des facteurs de correction des exportations initiales de DISTRO
DISTR(I,J) Matrice de la Distribution a posteriori ajustee par moteur I et par région J
DIST_Expo(Moteur,Expo) Matrice des Distributions a posteriori entre les moteurs J par région I
MATAJ(I,J) Matrice ajustes par région I et par les moteurs J
OBJ Fonction objectif ;

EQUATIONS
EQBRA(Moteur) Contrainte de respect de la distribution par région (totaux marginaux de lignes)
EQ_Expo(Expo) Contrainte de respect de la distribution par moteur (totaux marginaux de colonnes)
EQOBJ Equation du critere de distance a minimiser ;

ZED.LO(Moteur,Expo) = EPSILON ;
ZED.L(Moteur,Expo) = SUM(MoteurJ,DISTRO(MoteurJ,"TOTAL"))/SUM((MoteurJ,ExpoJ),DISTRO(MoteurJ,ExpoJ)) ;

DISPLAY ZED.L ;

EQBRA(Moteur).. SUM(Expo,DISTRO(Moteur,Expo)*ZED(Moteur,Expo)) =E= DISTRO(Moteur,"TOTAL") ;
EQ_Expo(Expo).. SUM(Moteur,DISTRO(Moteur,Expo)*ZED(Moteur,Expo)) =E= DISTRO("Expo",Expo) ;

EQOBJ.. OBJ =E= SUM((Moteur,Expo),ABS(DISTRO(Moteur,Expo))*ZED(Moteur,Expo)*log(ZED(Moteur,Expo))) ;

OPTION ITERLIM=100000 ;
OPTION DECIMALS=5 ;
MODEL AJUS_Expo /ALL/ ;
OPTION NLP=CONOPT3 ;
SOLVE AJUS_Expo USING NLP MINIMIZING OBJ ;

MATAJ.L(Moteur,Expo) = DISTRO(Moteur,Expo)*ZED.L(Moteur,Expo)*100000 ;
MATAJ.L(Moteur,"TOTAL") = DISTRO(Moteur,"TOTAL")*100000 ;
MATAJ.L("Expo",Expo) = DISTRO("Expo",Expo)*100000 ;
MATAJ.L("Expo","TOTAL") = MATAJ.L("Expo","TOTAL") ;

DIST_Expo.L(Moteur,Expo)$(SUM(ExpoJ,MATAJ.L(Moteur,ExpoJ)) NE 0) = MATAJ.L(Moteur,Expo)/SUM(ExpoJ,MATAJ.L(Moteur,ExpoJ)) ;

DIST_Expo.L(Moteur,Expo)$(SUM(ExpoJ,MATAJ.L(Moteur,ExpoJ)) EQ 0) = 0 ;

*$ontext
file Resul /
* Nom du ficher a creer
Exportation_reg.xls/ ;
* Separateur de colonne (6=tabulateur)
Resul.pc=6 ;
* Nombre de decimales
Resul.nd=3 ;
*nombre de colonnes
* Resul.pw=130

put Resul ;
$ontext
put 'MATRICE DES EXPORTATIONS AJUSTES PAR REGION (en DT)' // ;
put ' ' loop(Expo, put Expo.TE(Expo)) put / ;
loop(I, put I.tl loop(Expo, put MATAJ.L(I,Expo)) put /) ;
put / ;
$offtext
put 'MATRICE DES EXPORTATIONS AJUSTEES PAR REGION (en DT)' // ;
put ' ' loop(j, put j.TE(j)) put / ;
loop(i, put i.tl loop(j, put MATAJ.L(i,j)) put /) ;
put / ;

put 'Ancienne Matrice (en DT)' // ;
put ' ' loop(j, put j.TE(j)) put / ;
loop(i, put i.tl loop(j, put Donnees(i,j)) put /) ;
put / ;

As you can see, i exported my Output in Excel format.

The problem is: in the Excel format, the numbers (they are big numbers) are expressed in scientific notation (like: 170624 e+8), which is not my goal. I wanna have the full normal numbers expressed.

My question is: is there any GAMS instruction i can add to deal with this ? Or, is there any Excel trick I should know about ?

Thanks for the help

Re: Creating a Subset

Posted: Tue May 12, 2020 6:56 am
by bussieck
I suggest that you use the code display feature when pasting GAMS model source (or use the attachment facility). If you paste it as you did e.g. alignments of tables disappear and one has trouble compiling.

You can just add "Resul.nw=18 ;" to turn your numbers into fixed format.

-Michael

Re: Creating a Subset

Posted: Tue May 12, 2020 12:03 pm
by Essouaied Aziz
I apprecitae the help.
Thanks.