|
View:
New views
9 Messages
—
Rating Filter:
Alert me
|
|
|
CSV outputting MathProg for summary report mapulationHi,
I don't know how to exactly to convert this AMPL code to MathProg to get the desired CSV table. In AMPL ############ table tblWoodflowSummary OUT "ODBC" "Otago.mdb" "tblWoodflowSummary": {t in PERIOD} -> [Period],sum {(t,i,j) in HARVEST} Y[t,i,j] ~ ClearfellArea, {p in PRODUCT: Status[p] in YIELD} <sum {(t,i,j) in HARVEST} Y[t,i,j]*Yield[p,i,j] ~ (p)>; write table tblWoodflowSummary; The desire tables in CSV outlooks like this: Period ClearfellArea TRV P1P2 SLOG PULP 1 222 23 34 23 12 2 22 23 31 23 12 3 10 23 30 23 12 4 222 23 34 23 12 5 22 23 34 23 12 . . 60 where TRV, P1P2 SLOG and PULP are the PRODUCT. Now, how to we do write in MatProg? Here are incomplete and working script. table tab_WoodflowSummary{(t,i,j) in HARVEST} OUT "CSV" "WoodFlowSummary.csv" : t ~ Period, sum {(t,i,j) in HARVEST} Y[t,i,j] ~ ClearfellArea regards, Noli _______________________________________________ Help-glpk mailing list Help-glpk@... https://lists.gnu.org/mailman/listinfo/help-glpk |
|
|
Re: CSV outputting MathProg for summary report mapulationHi,
This first part is working now. table tab_WoodflowSummary{t in PERIOD} OUT "CSV" "WoodFlowSummary.csv" : t ~ Period, (sum {(t,i,j) in HARVEST} Y[t,i,j]) ~ ClearfellArea; Period,ClearfellArea 1,3086.19821682923 2,1268.43555053816 3,1414.81034598901 4,1050.01727432133 5,996.278617016041 6,1108.69319799071 7,1304.17092396292 8,1541.74787266007 However, I could not figure out how to do, this part. {p in PRODUCT: Status[p] in YIELD} <sum {(t,i,j) in HARVEST} Y[t,i,j]*Yield[p,i,j] ~ (p)>; As you can see in the output, it involve transposing and summing. > Period ClearfellArea TRV P1P2 SLOG PULP > 1 222 23 34 23 12 > 2 22 23 31 23 12 > 3 10 23 30 23 12 > 4 222 23 34 23 12 > 5 22 23 34 23 12 > . > . > 60 Noli > I don't know how to exactly to convert this AMPL code to MathProg to > get the desired CSV table. > > In AMPL > ############ > table tblWoodflowSummary OUT "ODBC" "Otago.mdb" "tblWoodflowSummary": > > {t in PERIOD} -> [Period],sum {(t,i,j) in HARVEST} Y[t,i,j] ~ > ClearfellArea, > > {p in PRODUCT: Status[p] in YIELD} <sum {(t,i,j) in HARVEST} > Y[t,i,j]*Yield[p,i,j] ~ (p)>; > > write table tblWoodflowSummary; > > > > The desire tables in CSV outlooks like this: > > Period ClearfellArea TRV P1P2 SLOG PULP > 1 222 23 34 23 12 > 2 22 23 31 23 12 > 3 10 23 30 23 12 > 4 222 23 34 23 12 > 5 22 23 34 23 12 > . > . > 60 > > where TRV, P1P2 SLOG and PULP are the PRODUCT. > > Now, how to we do write in MatProg? > > Here are incomplete and working script. > > > table tab_WoodflowSummary{(t,i,j) in HARVEST} OUT "CSV" > "WoodFlowSummary.csv" : > > t ~ Period, sum {(t,i,j) in HARVEST} Y[t,i,j] ~ ClearfellArea > > regards, > > Noli > _______________________________________________ Help-glpk mailing list Help-glpk@... https://lists.gnu.org/mailman/listinfo/help-glpk |
|
|
Re: CSV outputting MathProg for summary report mapulationThere is an alternative way in GMPL to write out CSV files. Use the printf function to create the CSV file.
Something like: printf " Period,ClearfellArea,TRV,P1P2,SLOG,PULP\n" > "filename.csv" printf {(t,i,j) in HARVEST} ": t, sum {(t,i,j) in HARVEST} Y[t,i,j] >> "filename.csv" -Marc -----Original Message----- From: help-glpk-bounces+marc.meketon=oliverwyman.com@... [mailto:help-glpk-bounces+marc.meketon=oliverwyman.com@...] On Behalf Of Noli Sicad Sent: Thursday, March 01, 2012 12:10 AM To: help-glpk@... Subject: [Help-glpk] CSV outputting MathProg for summary report mapulation Hi, I don't know how to exactly to convert this AMPL code to MathProg to get the desired CSV table. In AMPL ############ table tblWoodflowSummary OUT "ODBC" "Otago.mdb" "tblWoodflowSummary": {t in PERIOD} -> [Period],sum {(t,i,j) in HARVEST} Y[t,i,j] ~ ClearfellArea, {p in PRODUCT: Status[p] in YIELD} <sum {(t,i,j) in HARVEST} Y[t,i,j]*Yield[p,i,j] ~ (p)>; write table tblWoodflowSummary; The desire tables in CSV outlooks like this: Period ClearfellArea TRV P1P2 SLOG PULP 1 222 23 34 23 12 2 22 23 31 23 12 3 10 23 30 23 12 4 222 23 34 23 12 5 22 23 34 23 12 . . 60 where TRV, P1P2 SLOG and PULP are the PRODUCT. Now, how to we do write in MatProg? Here are incomplete and working script. table tab_WoodflowSummary{(t,i,j) in HARVEST} OUT "CSV" "WoodFlowSummary.csv" : t ~ Period, sum {(t,i,j) in HARVEST} Y[t,i,j] ~ ClearfellArea regards, Noli _______________________________________________ Help-glpk mailing list Help-glpk@... https://lists.gnu.org/mailman/listinfo/help-glpk This e-mail and any attachments may be confidential or legally privileged. If you received this message in error or are not the intended recipient, you should destroy the e-mail message and any attachments or copies, and you are prohibited from retaining, distributing, disclosing or using any information contained herein. Please inform us of the erroneous delivery by return e-mail. Thank you for your cooperation. _______________________________________________ Help-glpk mailing list Help-glpk@... https://lists.gnu.org/mailman/listinfo/help-glpk |
|
|
Re: CSV outputting MathProg for summary report mapulationSecond line was incorrect. A better approximation is:
printf " Period,ClearfellArea,TRV,P1P2,SLOG,PULP\n" > "filename.csv" printf {(t,i,j) in HARVEST}: "%d,%f\n" t, sum {(t,i,j) in HARVEST} Y[t,i,j] >> "filename.csv" -----Original Message----- From: help-glpk-bounces+marc.meketon=oliverwyman.com@... [mailto:help-glpk-bounces+marc.meketon=oliverwyman.com@...] On Behalf Of Meketon, Marc Sent: Thursday, March 01, 2012 2:29 AM To: Noli Sicad; help-glpk@... Subject: Re: [Help-glpk] CSV outputting MathProg for summary report mapulation There is an alternative way in GMPL to write out CSV files. Use the printf function to create the CSV file. Something like: printf " Period,ClearfellArea,TRV,P1P2,SLOG,PULP\n" > "filename.csv" printf {(t,i,j) in HARVEST} ": t, sum {(t,i,j) in HARVEST} Y[t,i,j] >> "filename.csv" -Marc -----Original Message----- From: help-glpk-bounces+marc.meketon=oliverwyman.com@... [mailto:help-glpk-bounces+marc.meketon=oliverwyman.com@...] On Behalf Of Noli Sicad Sent: Thursday, March 01, 2012 12:10 AM To: help-glpk@... Subject: [Help-glpk] CSV outputting MathProg for summary report mapulation Hi, I don't know how to exactly to convert this AMPL code to MathProg to get the desired CSV table. In AMPL ############ table tblWoodflowSummary OUT "ODBC" "Otago.mdb" "tblWoodflowSummary": {t in PERIOD} -> [Period],sum {(t,i,j) in HARVEST} Y[t,i,j] ~ ClearfellArea, {p in PRODUCT: Status[p] in YIELD} <sum {(t,i,j) in HARVEST} Y[t,i,j]*Yield[p,i,j] ~ (p)>; write table tblWoodflowSummary; The desire tables in CSV outlooks like this: Period ClearfellArea TRV P1P2 SLOG PULP 1 222 23 34 23 12 2 22 23 31 23 12 3 10 23 30 23 12 4 222 23 34 23 12 5 22 23 34 23 12 . . 60 where TRV, P1P2 SLOG and PULP are the PRODUCT. Now, how to we do write in MatProg? Here are incomplete and working script. table tab_WoodflowSummary{(t,i,j) in HARVEST} OUT "CSV" "WoodFlowSummary.csv" : t ~ Period, sum {(t,i,j) in HARVEST} Y[t,i,j] ~ ClearfellArea regards, Noli _______________________________________________ Help-glpk mailing list Help-glpk@... https://lists.gnu.org/mailman/listinfo/help-glpk This e-mail and any attachments may be confidential or legally privileged. If you received this message in error or are not the intended recipient, you should destroy the e-mail message and any attachments or copies, and you are prohibited from retaining, distributing, disclosing or using any information contained herein. Please inform us of the erroneous delivery by return e-mail. Thank you for your cooperation. _______________________________________________ Help-glpk mailing list Help-glpk@... https://lists.gnu.org/mailman/listinfo/help-glpk This e-mail and any attachments may be confidential or legally privileged. If you received this message in error or are not the intended recipient, you should destroy the e-mail message and any attachments or copies, and you are prohibited from retaining, distributing, disclosing or using any information contained herein. Please inform us of the erroneous delivery by return e-mail. Thank you for your cooperation. _______________________________________________ Help-glpk mailing list Help-glpk@... https://lists.gnu.org/mailman/listinfo/help-glpk |
|
|
Re: CSV outputting MathProg for summary report mapulationThanks for the suggestion.
> Second line was incorrect. A better approximation is: > > printf " Period,ClearfellArea,TRV,P1P2,SLOG,PULP\n" > "filename.csv" > printf {(t,i,j) in HARVEST}: "%d,%f\n" t, sum {(t,i,j) in HARVEST} Y[t,i,j] >>> "filename.csv" > However, TRV, P1P2, SLOG, PULP are inputs so it changes from time to time. It could not be hardcoded. Some of the data sets for case studies, the YIELD may have PRODUCTS where are P1, P2, SLOG1, SLOG2, K1, K2, C1, C2, PULP. Any suggestion how to do this using for {p in PRODUCT} { } syntax. ####################### {p in PRODUCT: Status[p] in YIELD} <sum {(t,i,j) in HARVEST} Y[t,i,j]*Yield[p,i,j] ~ (p)>; Thanks. Noli _______________________________________________ Help-glpk mailing list Help-glpk@... https://lists.gnu.org/mailman/listinfo/help-glpk |
|
|
Re: CSV outputting MathProg for summary report mapulationThis is the data set for the problem.
set PRODUCT:= TRV SCOST PCOST P1P2 SLOG PULP CFREV LCOST TCOST SACOST RCOST; #param Type{PRODUCT} symbolic; # Product (Final), Thinning (Intermediate), Residue param Type:= TRV Final SCOST Intermediate PCOST Intermediate P1P2 Final SLOG Final PULP Final CFREV Final LCOST Final TCOST Final SACOST Final RCOST Final; #param Status{PRODUCT} symbolic; # Revenue, Cost, Yield, Ignore param Status:= TRV Yield SCOST Cost PCOST Cost P1P2 Yield SLOG Yield PULP Yield CFREV Revenue LCOST Cost TCOST Cost SACOST Cost RCOST Cost ; Noli On 3/1/12, Noli Sicad <nsicad@...> wrote: > Thanks for the suggestion. > >> Second line was incorrect. A better approximation is: >> >> printf " Period,ClearfellArea,TRV,P1P2,SLOG,PULP\n" > "filename.csv" >> printf {(t,i,j) in HARVEST}: "%d,%f\n" t, sum {(t,i,j) in HARVEST} >> Y[t,i,j] >>>> "filename.csv" >> > > However, TRV, P1P2, SLOG, PULP are inputs so it changes from time to > time. It could not be hardcoded. Some of the data sets for case > studies, the YIELD may have PRODUCTS where are P1, P2, SLOG1, SLOG2, > K1, K2, C1, C2, PULP. > > Any suggestion how to do this using > > for {p in PRODUCT} { } syntax. > > ####################### > > {p in PRODUCT: Status[p] in YIELD} <sum {(t,i,j) in HARVEST} > Y[t,i,j]*Yield[p,i,j] ~ (p)>; > > Thanks. > > Noli > _______________________________________________ Help-glpk mailing list Help-glpk@... https://lists.gnu.org/mailman/listinfo/help-glpk |
|
|
Re: CSV outputting MathProg for summary report mapulationPrinting out the CSV header using printf is probably doable with a statement like:
printf {p in PRODUCT} : "%s," PRODUCT[p] > "filename.csv" ; #no "new line" printf "DUMMY\n; #last one has the new line The DUMMY was added because the last comma would be hanging out by itself without it. I would guess that you could dump out the data this way as well, but add a dummy value at the end. This is somewhat convoluted and probably there is a better way. -----Original Message----- From: Noli Sicad [mailto:nsicad@...] Sent: Thursday, March 01, 2012 2:55 AM To: Meketon, Marc Cc: help-glpk@... Subject: Re: [Help-glpk] CSV outputting MathProg for summary report mapulation This is the data set for the problem. set PRODUCT:= TRV SCOST PCOST P1P2 SLOG PULP CFREV LCOST TCOST SACOST RCOST; #param Type{PRODUCT} symbolic; # Product (Final), Thinning (Intermediate), Residue param Type:= TRV Final SCOST Intermediate PCOST Intermediate P1P2 Final SLOG Final PULP Final CFREV Final LCOST Final TCOST Final SACOST Final RCOST Final; #param Status{PRODUCT} symbolic; # Revenue, Cost, Yield, Ignore param Status:= TRV Yield SCOST Cost PCOST Cost P1P2 Yield SLOG Yield PULP Yield CFREV Revenue LCOST Cost TCOST Cost SACOST Cost RCOST Cost ; Noli On 3/1/12, Noli Sicad <nsicad@...> wrote: > Thanks for the suggestion. > >> Second line was incorrect. A better approximation is: >> >> printf " Period,ClearfellArea,TRV,P1P2,SLOG,PULP\n" > "filename.csv" >> printf {(t,i,j) in HARVEST}: "%d,%f\n" t, sum {(t,i,j) in HARVEST} >> Y[t,i,j] >>>> "filename.csv" >> > > However, TRV, P1P2, SLOG, PULP are inputs so it changes from time to > time. It could not be hardcoded. Some of the data sets for case > studies, the YIELD may have PRODUCTS where are P1, P2, SLOG1, SLOG2, > K1, K2, C1, C2, PULP. > > Any suggestion how to do this using > > for {p in PRODUCT} { } syntax. > > ####################### > > {p in PRODUCT: Status[p] in YIELD} <sum {(t,i,j) in HARVEST} > Y[t,i,j]*Yield[p,i,j] ~ (p)>; > > Thanks. > > Noli > This e-mail and any attachments may be confidential or legally privileged. If you received this message in error or are not the intended recipient, you should destroy the e-mail message and any attachments or copies, and you are prohibited from retaining, distributing, disclosing or using any information contained herein. Please inform us of the erroneous delivery by return e-mail. Thank you for your cooperation. _______________________________________________ Help-glpk mailing list Help-glpk@... https://lists.gnu.org/mailman/listinfo/help-glpk |
|
|
Re: CSV outputting MathProg for summary report mapulationFinally got it.
Here's the right mathprog script for the problem. #############################################3 param f,symbolic := "WoodFlowSummaryR.csv"; printf "Writing output to %s\n", f; printf "Period,ClearfellArea" > f; for {p in PRODUCT: Status[p] in YIELD} printf ",%s", p >> f; printf "\n" >> f; for{t in PERIOD} { printf "%d,%f",t, (sum {(t,i,j) in HARVEST} Y[t,i,j])>>f; for {p in PRODUCT: Status[p] in YIELD} printf ",%f", (sum{(t,i,j) in HARVEST} Y[t,i,j]*Yield[p,i,j])>>f; printf "\n" >>f; } ##############################3 Here's the table now: Period,ClearfellArea,TRV,P1P2,SLOG,PULP 1,3086.198217,1382637.725042,102798.000000,726261.758977,553577.966065 2,1268.435551,510967.374538,65270.600000,241168.957090,204527.817449 3,1414.810346,499699.031451,73155.626951,226543.404499,200000.000000 4,1050.017274,500236.363522,88775.432342,211460.931180,200000.000000 5,996.278617,500455.414672,105285.098810,195170.315862,200000.000000 6,1108.693198,533655.860669,125261.038572,195129.472586,213265.349511 7,1304.170924,620943.788743,150564.046286,222190.315724,248189.426733 8,1541.747873,732194.846730,180771.895544,258734.268933,292688.682253 9,1820.969969,867194.215303,217282.674652,303194.183828,346717.356822 10,2184.610549,1037886.398363,260252.789583,363014.506653,414619.102127 . . 45 It needs just formatting now. Noli On 3/1/12, Meketon, Marc <Marc.Meketon@...> wrote: > Printing out the CSV header using printf is probably doable with a statement > like: > > printf {p in PRODUCT} : "%s," PRODUCT[p] > "filename.csv" ; #no "new line" > printf "DUMMY\n; #last one has the new line > > The DUMMY was added because the last comma would be hanging out by itself > without it. > > I would guess that you could dump out the data this way as well, but add a > dummy value at the end. > > This is somewhat convoluted and probably there is a better way. > > -----Original Message----- > From: Noli Sicad [mailto:nsicad@...] > Sent: Thursday, March 01, 2012 2:55 AM > To: Meketon, Marc > Cc: help-glpk@... > Subject: Re: [Help-glpk] CSV outputting MathProg for summary report > mapulation > > This is the data set for the problem. > > > set PRODUCT:= > > TRV > > SCOST > > PCOST > > P1P2 > > SLOG > > PULP > > CFREV > > LCOST > > TCOST > > SACOST > > RCOST; > > > > #param Type{PRODUCT} symbolic; # Product (Final), > Thinning > (Intermediate), Residue > > > > param Type:= > > TRV Final > > SCOST Intermediate > > PCOST Intermediate > > P1P2 Final > > SLOG Final > > PULP Final > > CFREV Final > > LCOST Final > > TCOST Final > > SACOST Final > > RCOST Final; > > > > #param Status{PRODUCT} symbolic; # Revenue, Cost, Yield, Ignore > > param Status:= > > TRV Yield > > SCOST Cost > > PCOST Cost > > P1P2 Yield > > SLOG Yield > > PULP Yield > > CFREV Revenue > > LCOST Cost > > TCOST Cost > > SACOST Cost > > RCOST Cost > > ; > > Noli > > On 3/1/12, Noli Sicad <nsicad@...> wrote: >> Thanks for the suggestion. >> >>> Second line was incorrect. A better approximation is: >>> >>> printf " Period,ClearfellArea,TRV,P1P2,SLOG,PULP\n" > "filename.csv" >>> printf {(t,i,j) in HARVEST}: "%d,%f\n" t, sum {(t,i,j) in HARVEST} >>> Y[t,i,j] >>>>> "filename.csv" >>> >> >> However, TRV, P1P2, SLOG, PULP are inputs so it changes from time to >> time. It could not be hardcoded. Some of the data sets for case >> studies, the YIELD may have PRODUCTS where are P1, P2, SLOG1, SLOG2, >> K1, K2, C1, C2, PULP. >> >> Any suggestion how to do this using >> >> for {p in PRODUCT} { } syntax. >> >> ####################### >> >> {p in PRODUCT: Status[p] in YIELD} <sum {(t,i,j) in HARVEST} >> Y[t,i,j]*Yield[p,i,j] ~ (p)>; >> >> Thanks. >> >> Noli >> > > This e-mail and any attachments may be confidential or legally privileged. > If you received this message in error or are not the intended recipient, you > should destroy the e-mail message and any attachments or copies, and you are > prohibited from retaining, distributing, disclosing or using any information > contained herein. Please inform us of the erroneous delivery by return > e-mail. Thank you for your cooperation. > _______________________________________________ Help-glpk mailing list Help-glpk@... https://lists.gnu.org/mailman/listinfo/help-glpk |
|
|
Re: CSV outputting MathProg for summary report mapulation> I don't know how to exactly to convert this AMPL code to MathProg to > get the desired CSV table. > > In AMPL > ############ > table tblWoodflowSummary OUT "ODBC" "Otago.mdb" "tblWoodflowSummary": > > {t in PERIOD} -> [Period],sum {(t,i,j) in HARVEST} Y[t,i,j] ~ ClearfellArea, > > {p in PRODUCT: Status[p] in YIELD} <sum {(t,i,j) in HARVEST} > Y[t,i,j]*Yield[p,i,j] ~ (p)>; > > write table tblWoodflowSummary; > > > > The desire tables in CSV outlooks like this: > > Period ClearfellArea TRV P1P2 SLOG PULP > 1 222 23 34 23 12 > 2 22 23 31 23 12 > 3 10 23 30 23 12 > 4 222 23 34 23 12 > 5 22 23 34 23 12 > . > . > 60 > > where TRV, P1P2 SLOG and PULP are the PRODUCT. > > Now, how to we do write in MatProg? > > Here are incomplete and working script. > > > table tab_WoodflowSummary{(t,i,j) in HARVEST} OUT "CSV" "WoodFlowSummary.csv" : > > t ~ Period, sum {(t,i,j) in HARVEST} Y[t,i,j] ~ ClearfellArea > > regards, > MathProg does not allow creating tables whose fields are unknown at the compile time (i.e. like in your AMPL example). On the other hand, using such a table structure is not a good idea (at least in MathProg context, where data tables represent some relations between predefined sets). You might use, for example, the following table structure: Period ClearfellArea PRODUCT VALUE ... ... TRV 123.456 ... ... P1P2 456.123 ... ... SLOG ... ... ... PULP ... etc. that would resolve the issue. _______________________________________________ Help-glpk mailing list Help-glpk@... https://lists.gnu.org/mailman/listinfo/help-glpk |
| Free embeddable forum powered by Nabble | Forum Help |