In a GAMS program, I have a table with two rows and ten columns. the first row is the prices and the second row is the profit. I use the "Smax" to find the maximum profit but I can not find the price consistent with maximum profit please help me to find the corresponding price

asked 02 Jun '14, 17:04

aazad's gravatar image

accept rate: 0%

@aazad: Do you need the corresponding index or would just the corresponding price suffice as well? Also, does the profit array contain unique elements or not?

(04 Jun '14, 15:22) Ehsan ♦


I hope this solves your problem:

set row / price, profit /
    col / c0*c9         /
    idxMaxProfit(col)    ;

parameter t(row,col),
* Random data
t(row,col) = uniformInt(2,8);

scalar maxProfit;
maxProfit = smax(col,t('profit',col));

* All columns that have the maximum profit
idxMaxProfit(col)            = t('profit',col) = maxProfit;
* Prices of the columns with the maximum profit
priceMaxProfit(idxMaxProfit) = t('price',idxMaxProfit)

display t,idxMaxProfit,priceMaxProfit;

Best, Lutz


answered 11 Jun '14, 12:13

Lutz%20Westermann's gravatar image

Lutz Westermann
accept rate: 0%


@Lutz, great to see GAMS people here. Your input is most needed!

(11 Jun '14, 13:53) Marco Luebbecke ♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 02 Jun '14, 17:04

Seen: 1,825 times

Last updated: 11 Jun '14, 13:53

OR-Exchange! Your site for questions, answers, and announcements about operations research.