[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-glpk] Transposing result table using MathProg
From: |
Noli Sicad |
Subject: |
Re: [Help-glpk] Transposing result table using MathProg |
Date: |
Thu, 7 Jan 2010 09:08:24 +0700 |
Hi Xypron,
Thank you very much for this mathprog script.
Sorry for not reply back ASAP. I did not see it in google mail inbox.
I just saw the reply until I visited glpk archive.
I think this is really good. I have been asking the R people how to do
this. But they could not produce the needed result. R package reshape
-cast and melt could not do it.
I think you should put the mathprog help scripts in your website as
GLPK/MathProg Wiki.
Please disregard, my new posting about "Matrix (premultification) in MathProg".
Thanks again.
Regards, Noli
On 1/6/10, xypron <address@hidden> wrote:
>
> Hello Noli,
>
> the model belows will read your input data from a csv file and output it to
> another csv file with one column per value of period.
>
> Best regards
>
> Xypron
>
> http://old.nabble.com/file/p27026678/input.csv input.csv
> http://old.nabble.com/file/p27026678/test.mod test.mod
>
> # Read a csv file and output it as another csv file
> # with generation of columns for each value of
> # one of the indices.
> #
> # output csv f
> param f,symbolic := "output.csv";
> # CROP_ID CROPTYPE Period Ini_Age
> set S dimen 4;
> # Period
> set P := setof{(i,j,k,l) in S} k;
> # CROP_ID CROPTYPE Ini_Age
> set Q := setof{(i,j,k,l) in S} (i,j,l);
> # Area_Cut
> param a{S};
>
> table tin IN 'CSV' 'input.csv' :
> S <- [CROP_ID, CROPTYPE, Period, Ini_Age], a~Area_Cut;
>
> solve;
>
> printf "Writing output to %s\n", f;
>
> printf "CROP_ID,CROPTYPE,Ini_Age" > f;
> for{p in P} printf ",Period_%d", p >> f;
> printf "\n" >> f;
>
> for{(i,j,k) in Q} {
> printf "%s,%s,%s",i,j,k >> f;
> for{p in P} printf ",%f", if (i,j,p,k) in S then a[i,j,p,k] else 0 >>f;
> printf "\n" >>f;
> }
> end;
>
> input.csv
> =======
> CROP_ID,CROPTYPE,Period,Ini_Age,Area_Cut
> 83,SORI,1,31,528.2465512
> 84,SORI,1,32,74.55179899
> 85,SORI,1,33,72.45778618
> 86,SORI,1,34,139.5272947
> 82,SORI,2,28,1.711642933
> 83,SORI,2,29,2.500000071
> 84,SORI,2,30,432.5139327
> 93,SORM,2,35,316.8422545
> 62,OTRM,3,30,64.60526438
> 82,SORI,3,27,26.93674606
> 3,SORM,3,35,223.3658345
> 82,SORI,4,26,2.500000071
> 4,SORM,4,34,1008.643
> 5,OTRI,5,25,32.42603214
> 5,OTRM,5,29,65.9031344
> 5,SORM,5,32,223.1489321
> 5,SORM,5,33,72.59203041
> 5,SORM,5,35,222.8402746
> 6,OTRI,6,22,2.499999851
> 6,OTRI,6,23,3.374626509
> 6,OTRI,6,24,96.13462257
> 6,OTRM,6,26,830.7463641
> 6,OTRM,6,27,731.6228643
> 6,OTRM,6,28,16.3519762
> 7,OTRM,7,26,1636.5693
> 8,OTRM,8,26,553.0050146
> 9,OTRM,9,26,894.414033
> 10,OTRM,10,24,38.72597099
> 10,OTRM,10,25,308.6452707
> 10,OTRM,10,26,786.1761969
> 10,SORM,10,31,235.8360136
>
>
>
>
> Noli Sicad wrote:
>>
>> Hi,
>>
>> I have dealing a lot of manual format of my LP result inorder that I
>> can use the data for the map purpose. I did to run my LP results into
>> graphs and maps. I am working on forest management / forest carbon
>> estate modelling and maps are very important to visualise multi period
>> results of the LP model. The period that I am running is 1 to 100
>> years.
>>
>> This is the LP format as output by MathProg.
>>
>> From:
>> set A set B set C param
>>
>>
>> Desired table,
>> To:
>> set A set B param set C
>>
>>
>> Sample result and desired table (below)
>>
>> How do I do in MathProg? As we know there is transpose (tr.) in Data
>> section. I hope this can be use in the result sectio as well. But
>> probably somebody can show me how to do this in MathProg / GMPL.
>>
>> Thanks. Noli
>>
>>
>>
>> ~~~~~~~~
>> CROP_ID CROPTYPE Period Ini_Age Area_Cut
>> 83 SORI 1 31 528.2465512
>> 84 SORI 1 32 74.55179899
>> 85 SORI 1 33 72.45778618
>> 86 SORI 1 34 139.5272947
>> 82 SORI 2 28 1.711642933
>> 83 SORI 2 29 2.500000071
>> 84 SORI 2 30 432.5139327
>> 93 SORM 2 35 316.8422545
>> 62 OTRM 3 30 64.60526438
>> 82 SORI 3 27 26.93674606
>> 3 SORM 3 35 223.3658345
>> 82 SORI 4 26 2.500000071
>> 4 SORM 4 34 1008.643
>> 5 OTRI 5 25 32.42603214
>> 5 OTRM 5 29 65.9031344
>> 5 SORM 5 32 223.1489321
>> 5 SORM 5 33 72.59203041
>> 5 SORM 5 35 222.8402746
>> 6 OTRI 6 22 2.499999851
>> 6 OTRI 6 23 3.374626509
>> 6 OTRI 6 24 96.13462257
>> 6 OTRM 6 26 830.7463641
>> 6 OTRM 6 27 731.6228643
>> 6 OTRM 6 28 16.3519762
>> 7 OTRM 7 26 1636.5693
>> 8 OTRM 8 26 553.0050146
>> 9 OTRM 9 26 894.414033
>> 10 OTRM 10 24 38.72597099
>> 10 OTRM 10 25 308.6452707
>> 10 OTRM 10 26 786.1761969
>> 10 SORM 10 31 235.8360136
>>
>> Desired Table.
>> Period 1 Period 2 Period 3 Period 4
>> Period 5 Period 6 Period
>> 7 Period 8 Period 9 Period 10
>> CROP_ID CROPTYPE
>>
>> 83 SORI 31
>>
>> 84 SORI 32
>>
>> 85 SORI 33
>>
>> 86 SORI 34
>>
>> 82 SORI 28
>>
>> 83 SORI 29
>>
>> 84 SORI 30
>>
>> 93 SORM 35
>>
>> 62 OTRM 30
>>
>> 82 SORI 27
>>
>> 3 SORM 35
>>
>> 82 SORI 26
>> 4 SORM 34
>> 5 OTRI 25
>> 5 OTRM 29
>> 5 SORM 32
>> 5 SORM 33
>> 5 SORM 35
>> 6 OTRI 22
>> 6 OTRI 23
>> 6 OTRI 24
>> 6 OTRM 26
>> 6 OTRM 27
>> 6 OTRM 28
>> 7 OTRM 26
>> 8 OTRM 26
>> 9 OTRM
>> 26
>> 10 OTRM
>> 24
>> 10 OTRM
>> 25
>> 10 OTRM
>> 26
>> 10 SORM
>> 31
>>
>>
>> _______________________________________________
>> Help-glpk mailing list
>> address@hidden
>> http://lists.gnu.org/mailman/listinfo/help-glpk
>>
>>
>
> --
> View this message in context:
> http://old.nabble.com/Transposing-result-table-using-MathProg-tp27023621p27026678.html
> Sent from the Gnu - GLPK - Help mailing list archive at Nabble.com.
>
>
>
> _______________________________________________
> Help-glpk mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-glpk
>