SECTION 1.7 - Exercises 1-1

376 views
Skip to first unread message

shen...@gmail.com

unread,
Apr 22, 2017, 4:25:32 PM4/22/17
to AMPL Modeling Language
This is the problem statement:-

You are in charge of an advertising campaign for a new product, with a budget of $1 million.
You can advertise on TV or in magazines. One minute of TV time costs $20,000 and reaches 1.8
million potential customers; a magazine page costs $10,000 and reaches 1 million. You must sign
up for at least 10 minutes of TV time. How should you spend your budget to maximize your audience?
Formulate the problem in AMPL and solve it. Check the solution by hand using at least one
of the approaches described in Section 1.1.

---------------------------------------------
i am getting this errors :-

Section1.dat, line 9 (offset 146):
cost['price'] already defined
context: mag >>> 10000 <<< 0 ;

Section1.dat, line 9 (offset 156):
cost['time'] already defined
context: mag 10000 >>> 0 <<< ;

Section1.dat, line 12 (offset 188):
1 item(s) missing in last line of table, which starts with "10"
context: 10 >>> ; <<<
ampl:


------------------------------------------------------------

this is my Code:-

set method;


param Budget >=0;
param time {method}>=0;
param Time {method}>=0;
param cost {method} >=0;
param audiance{method}>=0;


var X {method} >=0;

maximize viewers : sum {i in method} (X[i]*audiance[i]);

s.t. TimeConst : sum {i in method} (X[i]* time[i])>= 10;
s.t. BudgConst: sum {i in method} (X[i] *cost[i])<=Budget;

#Data

data;

set method := tv mag;

param Budget:= 1000000;

param cost : price time :=
tv 20000 1

mag 10000 0 ;

param Time :=
10;


param audiance:=

tv 1800000
mag 1000000;


-------------------------------------------------
i would like to know what is wrong and how to fix it, i am still getting used to formulating using algebraic notation and still getting errors but i want to know if my code model/data is correct and how it can be improved;

Robert Fourer

unread,
Apr 23, 2017, 8:30:20 AM4/23/17
to am...@googlegroups.com
Your table of cost and time values should be

param: cost time :=
tv 20000 1
mag 10000 0 ;

Also it's not clear why you define "param Time" in your model since it's not used anywhere in the objective or constraints.

Bob Fourer
am...@googlegroups.com

shen...@gmail.com

unread,
Apr 23, 2017, 12:48:30 PM4/23/17
to AMPL Modeling Language
i removed the param Time since like you said it is not used, and thank you very much professor, however i have question:-

if i have a set of parameters like "t,c,v,b" can i write them like "param : t c v b:=" and make a table? and then recall each one of them like X[i]*t[i]? i am still new and learning AMPL and like it alot

Robert Fourer

unread,
Apr 24, 2017, 9:57:10 AM4/24/17
to am...@googlegroups.com
You can give the data for 4 params in one data statement. This is mainly useful if all 4 params are indexed over the same set. For an introduction to all of the AMPL data statements, see Chapter 9 of the AMPL book, http://ampl.com/BOOK/CHAPTERS/12-data.pdf; the format you are looking for is described on page 151.

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of shen...@gmail.com
Sent: Sunday, April 23, 2017 11:33 AM
To: AMPL Modeling Language

shen...@gmail.com

unread,
Apr 24, 2017, 1:23:58 PM4/24/17
to AMPL Modeling Language
thank you so much professor, i am still reading the book (chapter 4 currently).
also on a side note, thank you for sharing such an amazing software with us and hope you keep helping the community more professor, best wishes.
Reply all
Reply to author
Forward
0 new messages