1. More printf problems

Hello everybody -

Thanks to extensive help from Bob Pilkington and Ralf Niederhauser (aww -- I
don't have that last name right but I think you know whom I mean, and my
apologies again to Ralf) my big program is running now, and it generates the
'progsig' outputs more or less satisfactorily..  It is a version of Art
Adamson's traveling salesman program.  I changed the 'progsig' interval so
it is now generated every 10 minutes instead of every minute.  Eventually I
hope to remove it altogether.

However, there is still something missing in my understanding of the
'printf' command, because I'm not getting any printed output at all.
Ordinarily I wouldn't want much, but I do want enough at the present
debugging stage to disclose any bugs.  I'm left completely in the dark.

I changed the program to work with a smaller collection of cities (18
instead of 48), which should produce some kind of output on the screen from
time to time, and a printed message at longer intervals.  I'm getting
neither.  I added a short routine that should print out a list of the cities
in their current order at frequent intervals, whenever the program enters a
particular subroutine, and I'm getting exactly nothing -- zero -- nada --
zilch.  Here is the short routine:

temp = open("PRN", "w")
printf("temp", "%s\n", {"newTrip[1..9]})
printf("temp", "%s\n", {"newTrip[10..18]})
printf("temp", "%d\n\n", {count})
close("temp")

The 18 states that should print out in two lines are, basically, the
northeastern states of the U.S. plus all the states north of the Ohio River
and east of the Mississippi River.  Need a list?  Here they are: ME, NH, VT,
MA, RI, CT, NY, NJ, DE, MD, VA, WV, PA, OH, IN, MI, WI, IL.  This is the
initial order with which the main program begins; it should juggle the
order, display any new order on the screen (now temporarily on the printer
-- that doesn't work either) and if the new order has a shorter total
distance, print that order on paper.  The distance is the sum of the
distances between the capitals of those states -- hence the resemblance of
this program to the classic traveling-salesman problem.

The object of the main program is to find a minimum-length tour (or almost
minimum-length) of all 48 contiguous states of the U.S., subject to the
restriction that each leg of the tour passes between adjoining states only.
It is supposed to approximate the true minimum length only; the absolute
minimum would take hundreds of years to compute.  There are a number of
other restrictions that follow from the adjoining requirement; I won't go
into them now, because this is supposed to be a short note.

There was an article about this project in the Amateur Scientist section of
Scientific American last March.  That article described an algorithm in C;
Art Adamson revised the program in Euphoria and has recently produced an
improved version, together with one from someone in Eastern Europe who
doesn't know English, and whose program therefore I haven't yet been able to
unravel.

If you need additional information about this, some of it is available on
the Euphoria Listserv (Art's two versions) or directly on the Internet (from
the Society of Amateur Scientists).  If I can help you by describing parts
of it, let me know.  If you really, *really* want to see my entire program,
just ask; but it's a monster (eleven pages printed out) so I won't send it
unless you absolutely, positively have to see it.  My "short" version is
also eleven pages, but it works with a smaller data base and is shorter in
that respect only.

Again, I'm reasonably sure that the hangup is in my use or misuse of the
'printf' command.  There's something about it that I don't quite understand.
I hope somebody can ferret it out.  Thanks in advance.

Wally Riley
wryly at mindspring.com

new topic     » topic index » view message » categorize

2. Re: More printf problems

Wallace B. Riley wrote:
>
> zilch.  Here is the short routine:
>
> temp = open("PRN", "w")
> printf("temp", "%s\n", {"newTrip[1..9]})
         ^ temp should not be in quotation marks
         printf needs an integer variable here, not a string

> printf("temp", "%s\n", {"newTrip[10..18]})
                          ^ is this quotation mark a typo?

> printf("temp", "%d\n\n", {count})
> close("temp")
        ^ close needs an integer, the same way as printf

I would rewrite the code as:
integer temp
temp = open("PRN", "w")
if temp != -1 then  --check for printer ok
 printf(temp, "%s\n", {newTrip[1..9]})
 printf(temp, "%s\n", {newTrip[10..18]})
 printf(temp, "%d\n\n", {count})
 close(temp)
end if

I looked in library.doc for a better description of file handles, but it
was pretty vague.  It refers to a file number that is associated a with
an opened file.  This number is stored in an integer variable so it can
later be used for input or output to the file.  Procedures such as
printf, gets, or close use the file number to know which file to work
with.  I hope this helps.

--
                   _____         _____        _____
    ________      /\    \       /\    \      /\    \
   /   \    \    /  \____\     /  \____\    /  \____\
  /  _  \____\  /   / ___/_   /   /____/   /   / ___/_
 /  / \  |___| /   / /\____\ /    \    \  /   / /\____\
 \  \_/ /    / \   \/ / ___/_\     \    \ \   \/ / ___/_
  \    /____/   \    / /\    \\/\   \    \ \    / /\    \
   \   \    \    \   \/  \____\  \   \    \ \   \/  \____\
    \   \    \    \      /    /   \   \____\ \      /    /
     \   \____\    \    /    /     \  /    /  \    /    /
      \  /    /     \  /    /       \/____/    \  /    /
       \/____/       \/____/xseal at harborside.com\/____/

new topic     » goto parent     » topic index » view message » categorize

3. Re: More printf problems

>However, there is still something missing in my understanding of the
>'printf' command, because I'm not getting any printed output at all.
>Ordinarily I wouldn't want much, but I do want enough at the present
>debugging stage to disclose any bugs.  I'm left completely in the
>dark.
>
>I added a short routine that should print out a list of the
>cities in their current order at frequent intervals, whenever the
program
>enters a particular subroutine, and I'm getting exactly nothing -- zero
--
>nada -- zilch.  Here is the short routine:
>
>temp = open("PRN", "w")
>printf("temp", "%s\n", {"newTrip[1..9]})
>printf("temp", "%s\n", {"newTrip[10..18]})
>printf("temp", "%d\n\n", {count})
>close("temp")

I don't know if there was a mistype or not, but this is how it should
look:
temp = open("PRN", "w")                 -- Correct
printf(temp, "%s\n", {newTrip[1..9]})   -- Removed quotes from temp
printf(temp, "%s\n", {newTrip[10..18]}) -- and newTrip. Now correct.
printf(temp, "%d\n\n", {count})
close(temp)                             -- Removed quotes.

This should work just fine now. I don't know what goes on when printf()
is called, but it may be possible that since you used "temp" instead of
temp (you had the quotes), it was looking at the first element in the
sequence, 't', and was trying to write to file handle 't' (which equals
ASCII 116, so is equal to 116).... or not. Anyway, the above should work
now. If it doesn't print out, then the routine isn't being called. BTW,
newTrip[1..9] will print out the ASCII version of the values newTrip[1],
newTrip[2], etc. OIW, if newTrip[1] = 65, and newtrip[2] equals 66, then
you will see
AB
for the first two. If there are sub-sequences in each newTrip, then you
will get an error. A for loop would be much better (if I understand what
you want to do correctly:

temp = open("PRN", "w")
for temp_count = 1 to length(newTrip) --newTrip is a length 18 sequence,
right?
    printf(temp, "%s ", newTrip[temp_count])
end for
printf(temp, "\n%d\n\n", {count})
close(temp)

Another way to see if a routine is being called is using
with profile
after your includes. After running the program, look at ex.pro. There
will be numbers in front of each routine that was called, telling you how
many times it was called. (no number means it wasn't called)

Hope this helps.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu