RE: [AMPL 6077] Re: print path in AMPL

343 views
Skip to first unread message

Robert Fourer

unread,
Aug 28, 2012, 7:51:23 AM8/28/12
to am...@googlegroups.com

You can use "option ampl_include ..." to specify the location for model and data files, but it will not affect output files; in particular there is no option for changing the path to be assumed for a printed file.  There is a "cd" command however that changes the current directory, which does affect all file references, including output files.

 

You can always write the path to the output file explicitly, as in this example:

 

   display ... >"C:\AMPL\models\results.out";

 

If you have a lot of commands like this then you can define a new option, say,

 

   option outdir "C:\AMPL\models\results.out";

 

and then

 

   display ... >$outdir;

 

Or if you have different files you can define

 

   option outdir "C:\AMPL\models\";

 

and then

 

   display ... >($outdir & "results.out");

 

and similarly for other output files in that same directory.

 

Bob Fourer

4...@ampl.com

 

 

From: am...@googlegroups.com [mailto:am...@googlegroups.com]

On Behalf Of frankcw
Sent: Saturday, August 18, 2012 2:36 PM
To: am...@googlegroups.com
Subject: [AMPL 6077] Re: print path in AMPL

 

Dear AMPL friends,

 

I was wondering if anyone knows the answer. Basically, it is the relative path question. I have a run file with all the commands. I want to specify in the beginning the folder where my model and data are located. Then I want to print the result into a file in that folder. So many thanks,

 

Frank

On Monday, July 30, 2012 8:20:55 PM UTC-4, frankcw wrote:

Hello, I was wondering a simple question in ampl.

 

I change the path to be 

option include_path '...'

 

but once I print the result to some file, it is not in the folder I specify above. 

 

Anyone can help me on this?

 

Thanks a lot,

Frank

 

nouh elmitwally

unread,
Sep 2, 2012, 3:52:01 PM9/2/12
to am...@googlegroups.com
Hi Robert,

I am working on Ubuntu environment;

I have created this variable - as you have mentioned -
option outdir "/home/tests/results.out";

Then

display X> $outdir == It doesn't work and it prints no outputs on
that location


But when I say:

display X > "/home/tests/results.out"; = > It works with me.

What do you think about this problem?

Thanks,

Noah

On 9/1/12, frankcw <cui...@gmail.com> wrote:
> Dear Bob,
>
> I really appreciate your help. It saves a lot of troubles.
>
> Best regards,
> Frank
>
> On Tuesday, August 28, 2012 7:51:30 AM UTC-4, AMPL Optimization wrote:
>>
>> You can use "option ampl_include ..." to specify the location for model
>> and data files, but it will not affect output files; in particular there
>> is
>> no option for changing the path to be assumed for a printed file. There
>> is
>> a "cd" command however that changes the current directory, which does
>> affect all file references, including output files.
>>
>>
>>
>> You can always write the path to the output file explicitly, as in this
>> example:
>>
>>
>>
>> display ... >"C:\AMPL\models\results.out";
>>
>>
>>
>> If you have a lot of commands like this then you can define a new option,
>>
>> say,
>>
>>
>>
>> option outdir "C:\AMPL\models\results.out";
>>
>>
>>
>> and then
>>
>>
>>
>> display ... >$outdir;
>>
>>
>>
>> Or if you have different files you can define
>>
>>
>>
>> option outdir "C:\AMPL\models\";
>>
>>
>>
>> and then
>>
>>
>>
>> display ... >($outdir & "results.out");
>>
>>
>>
>> and similarly for other output files in that same directory.
>>
>>
>>
>> Bob Fourer
>>
>> 4...@ampl.com <javascript:>
>>
>>
>>
>>
>>
>> *From:* am...@googlegroups.com <javascript:> [mailto:
>> am...@googlegroups.com <javascript:>]
>>
>> *On Behalf Of *frankcw
>> *Sent:* Saturday, August 18, 2012 2:36 PM
>> *To:* am...@googlegroups.com <javascript:>
>> *Subject:* [AMPL 6077] Re: print path in AMPL
>>
>>
>>
>> Dear AMPL friends,
>>
>>
>>
>> I was wondering if anyone knows the answer. Basically, it is the relative
>>
>> path question. I have a run file with all the commands. I want to specify
>>
>> in the beginning the folder where my model and data are located. Then I
>> want to print the result into a file in that folder. So many thanks,
>>
>>
>>
>> Frank
>>
>> On Monday, July 30, 2012 8:20:55 PM UTC-4, frankcw wrote:
>>
>> Hello, I was wondering a simple question in ampl.
>>
>>
>>
>> I change the path to be
>>
>> option include_path '...'
>>
>>
>>
>> but once I print the result to some file, it is not in the folder I
>> specify above.
>>
>>
>>
>> Anyone can help me on this?
>>
>>
>>
>> Thanks a lot,
>>
>> Frank
>>
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "AMPL Modeling Language" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/ampl/-/PcmUmjS7GfwJ.
> To post to this group, send email to am...@googlegroups.com.
> To unsubscribe from this group, send email to
> ampl+uns...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/ampl?hl=en.
>
>

Robert Fourer

unread,
Sep 5, 2012, 5:18:38 AM9/5/12
to am...@googlegroups.com
To direct output to the filename stored in option outdir, specify

display X > ($outdir);

The parentheses (...) tell AMPL that the filename is given as a
string-valued expression, rather than as a literal name. When you write
instead "display X > $outdir;" the result is to send the output to a file
actually named "$outdir" (if your operating system permits this name).

Bob Fourer
4...@ampl.com
Reply all
Reply to author
Forward
0 new messages