Unable to generate Random numbers

133 views
Skip to first unread message

khan

unread,
Feb 2, 2017, 10:09:00 AM2/2/17
to AMPL Modeling Language
Hi,

I am unable to generate random number for my parameter d. Even every time I run my script I get the same value. I need different values fro param d for all d[m,k]. How can I do it?

CODE:
param d{ro in M, tj in K};


for{is in K,kl in M} {
   
let d[m,k] := Normal(375,125);
   
};


Robert Fourer

unread,
Feb 3, 2017, 5:50:11 PM2/3/17
to am...@googlegroups.com
You write "for {is in K, kl in M} {..." but then you do not use "is" or "kl" anywhere in the statement that is inside the for loop. Try writing instead

for {is in K, kl in M} {
let d[kl,is] := Normal(375,125);
};

To run the script again with a different sequence of normally distributed random values, change AMPL's option randseed from its default of 1 to something else; for example:

option randseed 7;

Also you can specify "option randseed 0;" to ask AMPL to use the system clock to set the random seed, which will have the effect of almost certainly giving a different sequence every time.

Bob Fourer
am...@goolglegroups.com

=======

Muhammad umar

unread,
Feb 4, 2017, 4:56:25 AM2/4/17
to am...@googlegroups.com, Victor Zverovich
Dear Bob,

Thank you for your input. But I am having the same problem. My model is giving the same fixed value again and again. I submit a job several times but getting same fixed results every time. I am not getting any clue where I have did wrong in my model.

I have also used the random seed in my model file. Still no random results are coming. Can you please have a look at my files? Attached for your considerations.
 

-- 
Best Regards 
M. Umar Khan

--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/_A6TQMhuC1w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+unsubscribe@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.

testdata.dat
testfile.mod

Muhammad umar

unread,
Feb 4, 2017, 5:00:44 AM2/4/17
to am...@googlegroups.com, Victor Zverovich
I am getting the same output again and again:

*************************************************************
File exists
You are using the solver gurobi_ampl.
Checking ampl.mod for gurobi_options...
Executing AMPL.
processing data.
processing commands.
Executing on neos-7.neos-server.org
rate[m,k] = 34.4348

d[m,k] = 960.097


Presolve eliminates 9 constraints and 119 variables.
Adjusted problem:
1 variable, all integer
0 constraints
1 linear objective; 1 nonzero.

Gurobi 7.0.1: threads=4
outlev=1
Optimize a model with 0 rows, 1 columns and 0 nonzeros
Variable types: 0 continuous, 1 integer (0 binary)
Coefficient statistics:
  Matrix range     [0e+00, 0e+00]
  Objective range  [6e+01, 6e+01]
  Bounds range     [0e+00, 0e+00]
  RHS range        [0e+00, 0e+00]
Found heuristic solution: objective -6e+31
Presolve time: 0.00s

Explored 0 nodes (0 simplex iterations) in 0.00 seconds
Thread count was 1 (of 64 available processors)

Solution count 1: -6e+31 
Pool objective bound 0

Model is unbounded
Warning: some integer variables take values larger than the maximum
         supported value (2000000000)
Best objective -6.000000000000e+31, best bound -, gap -
Gurobi 7.0.1: unbounded; variable.unbdd returned.
No basis.


-- 
Best Regards 
M. Umar Khan

Robert Fourer

unread,
Feb 6, 2017, 11:05:57 AM2/6/17
to am...@googlegroups.com
Your files show that you are making the same mistake as before. When you specify

param m:=3;
param k:=2;

for{is in K,kl in M} {
let d[m,k] := Normal(375*(is+1),125*(kl+.2));
};

you are just assigning values to d[3,2] over and over again. To assign values to all of the d params, you should instead write

for{is in K,kl in M} {
let d[kl,is] := Normal(375*(is+1),125*(kl+.2));
};

The same comments apply to h and rate. You will still need to set option randseed to get *different* random values on each run. It is not being set in your model or data file, however. Maybe you tried to set it from the command line but did not type the option statement correctly.

Bob Fourer
am...@googlegroups.com

=======

Muhammad umar

unread,
Feb 10, 2017, 11:24:44 AM2/10/17
to am...@googlegroups.com
Thank you Robert. That was too sily error for me.

-- 
Best Regards 
M. Umar Khan

--
Reply all
Reply to author
Forward
0 new messages