From kalle@gnupung.net Fri Feb 1 00:13:07 2002
From: kalle@gnupung.net (Kalle Svensson)
Date: Fri, 1 Feb 2002 01:13:07 +0100
Subject: [Tutor] read file and match string
In-Reply-To: <00f101c1aab0$c066e7a0$8cd91282@echo6>
References: <009201c1aa8b$1d48f060$8cd91282@echo6> <20020131225940.GA28719@sandra.lysator.liu.se> <00f101c1aab0$c066e7a0$8cd91282@echo6>
Message-ID: <20020201001307.GB28719@sandra.lysator.liu.se>
[Jim Ragsdale]
> Ok, im searching a log file from an Unreal Tournament server. it generates
> some output, but im really intested in 1 line:
> ScriptLog: [PLAYER_JOIN] {RS}]V{AD_l)OG_3 ip.address.omitted:1040 2600
>
> Each line will have ScriptLog: [PLAYER_JOIN] a name and ip:port and another
> number. The other lines are just different server events and other things of
> interest. i just want the ip address.
I see. That's a very nice project to get started with a language. To
me, the format suggests the use of string methods. I suppose there
are no other lines that contain "[PLAYER_JOIN]"? And there is always
the same number of spaces on each interesting line? In that cas, you
could try using something like:
in = open("file.in")
out = open("file.out", "w")
for line in in.xreadlines():
if line.find("[PLAYER_JOIN]"):
ip_and_port = line.split()[3]
out.write(ip_and_port + "\n")
With the example line above, this would write
ip.address.omitted:1040
to the output file. You can easily get rid of the port number by
doing
ip = ip_and_port.split(":")[0]
or, if the port number is always four digits
ip = ip_and_port[:-5]
I don't know if this will be any faster, but I guess it doesn't matter
that much. 0.4 seconds is probably fast enough?
> I did the regular expression because that is what i found on the net. Messed
> w/ it until i got it to match :) And I just upgraded to Python2.2. Using
> xreadline on a 1.56meg file on my 400celeron laptop takes about .4 sec.( Ran
> start = time.clock() before and finish = time.clock() after and took the
> difference) Also used the localtime function to write a date/time stamp in
> the logfile name(iplog.1.31.2002.5.35.log).
>
> Right now im trying to clean it up, use functions and stuff. do it right :)
> I would like to add some functionality as i go along. Say maybe determine if
> the log file has been reset and if it hasnt, start from where it left off
> last time. If it has been restarted, start fresh and maybe start a new
> output file.
Sounds very nice! When you get it ready, I suggest you submit it to
"Useless Python", a web site collecting python code snippets, tips and
challenges managed by a fellow tutor list member. And it's not all
useless... :) The address is http://www.lowerstandard.com/python/ .
Peace,
Kalle
--
Kalle Svensson (kalle@gnupung.net) - Laziness, impatience, hubris: Pick two!
English: http://www.gnupung.net/ Svenska: http://www.lysator.liu.se/~kalle/
Stuff: ["http://www.%s.org/" % x for x in "gnu debian python emacs".split()]
From overlord@netdoor.com Fri Feb 1 00:56:32 2002
From: overlord@netdoor.com (Jim Ragsdale)
Date: Thu, 31 Jan 2002 18:56:32 -0600
Subject: [Tutor] read file and match string
Message-ID: <010f01c1aabb$4aafb540$8cd91282@echo6>
[Kalle Svensson]
I will probably stick with what i have for now. it works. maybe i can get
about a 10meg file if nothing crashes and run some time trials on that.
That line is the only one w/ "[PLAYER_JOIN]" in it. and it is always
formatted the same. although names will be different lengths. Im just
writing out the whole line to the output file. If someone emails me about a
cheater and gives a name, i use find in notepad to search the iplogs and
then i can ban him from the server. Although in the name of space i will
probably go in and strip the first part of the line off.
I guess the ultimate setup would be to check the log from the server and
write the names and ip's to a database. If the name and ip address matched a
record in the database it would skip it. then i would not get duplicates.
everytime the game restarts players join again and i get duplicates. plus
there are many players that play there regularly. I could even add a counter
to see how many times each player is logged.
If i ever finish it or get it nice enough ill post!
From pythonhack@yahoo.com Fri Feb 1 00:52:01 2002
From: pythonhack@yahoo.com (pythonhack@yahoo.com)
Date: Thu, 31 Jan 2002 16:52:01 -0800
Subject: [Tutor] index list out of range
Message-ID: <19887498466.20020131165201@yahoo.com>
hey guys-
i'm writing a small address book program, and i think there's a
problem with the way the lists are structured and manipulated. i'm
getting a "list index out of range" error when i try to exit the
program (using the closeApp function).
help!
here's the code...
#!/usr/bin/env python
import sys, string, os
from time import sleep
newmaster = []
master = []
yeslist = ['y', 'Y', 'YES', 'yes']
nolist = ['n', 'N', 'NO', 'no']
##################################
## FUNCTIONS
##################################
#this function runs at the beginning of the script
#reads entire master address book into memory
def startApp():
print "Loading address book..."
sleep(3)
print " "
result = open('address.book', 'r')
for line in result.readlines():
master.append(line.split())
print "Address book loaded successfully."
print " "
return result
# print function returns formatted output
def printEntry(entry):
print entry[0], entry[1]
print entry[2]
print entry[3]
print entry[4]
if len(entry[5]) > 0:
print entry[5]
else:
print "
I generated a simannealfilec.dll with SWIG and also a python shadow class
named simannealfile.py. After running the python shadow class simannealfile.py
the following Error appers :
PythonWin 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit (Intel)] on win32.
Portions Copyright 1994-2001 Mark Hammond (
MarkH@ActiveState.com
) - see 'Help/About PythonWin' for further copyright information.
>>> Traceback (most recent call last):
File
"C:\Python21\Pythonwin\pywin\framework\scriptutils.py"
, line 394, in ImportFile
exec codeObj in __main__.__dict__
File "<auto import>", line 1, in ?
File
"C:\Arbeit_Diplomarbeit\__Optimierer\AG_TEMdll\simannealfile.py"
, line 2, in ?
import simannealfilec
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
Traceback (most recent call last):
File
"C:\Python21\Pythonwin\pywin\framework\scriptutils.py"
, line 301, in RunScript
exec codeObject in __main__.__dict__
File
"C:\Arbeit_Diplomarbeit\__Optimierer\AG_TEMdll\simannealfile.py"
, line 2, in ?
import simannealfilec
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
>>>
The File simannealfile.py looks in the beginning like that :
# This file was created automatically by SWIG.
import simannealfilec
class simanneal_varlist:
def __init__(self,*args):
self.this = apply(simannealfilec.new_simanneal_varlist,args)
self.thisown = 1
def __del__(self,simannealfilec=simannealfilec):
if getattr(self,'thisown',0):
simannealfilec.delete_simanneal_varlist(self)
def cleany(*args):
val = apply(simannealfilec.simanneal_varlist_cleany,args)
return val
I absolutly did´nt know what´s going wrong.
Have anyone got an idea ?
Thanks for your help
Marcus
--------------010006080804040709040704--
From urnerk@qwest.net Fri Feb 1 03:36:39 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 31 Jan 2002 19:36:39 -0800
Subject: [Tutor] More primes play
In-Reply-To: <3C59B912.6060300@venix.com>
References: <20020131211525.40906.qmail@web14101.mail.yahoo.com>
Message-ID: <4.2.0.58.20020131193011.00d23f10@pop3.norton.antivirus>
Continuing a thread of playing with prime number listings,
I'm appending a class definition I wrote awhile ago that
creates objects you can slice from, as show below, and
also iterate over, as also shown:
>>> from play import Primes
>>> myprimes = Primes()
>>> myprimes[0:10]
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
>>> myprimes[100]
547
>>> myprimes[3]
7
>>> for i in myprimes:
print i
if i > 2000: break
It's kind of like getting an object inside of which all
the primes already exist -- which is of course not true.
Through lazy evaluation (or "just in time" supply), it
internally iterates forward, appending new primes to its
internal list, in hopes of satisfying a user request.
But as we all know, trial-by-division (the algorithm
used here) wimps out when the going gets tough. So
this is mainly for playing with low primes (interpret
as you will what "low" means).
What's efficient about doing this as a class is that
the primes list doesn't go away between uses of the
instances, i.e. if you've computed up to the 100th prime,
and ask for the 200th, it's not going to start over from
scratch -- it'll just keep appending. Likewise, if you
ask for the 10th prime, but have already computed out to
the 100th, well, then there's no further computation
needed at all.
The whole iterator/generator business is best explored
in 2.2 and above, so yes, this is for you folks who are
at liberty to play with the latest snake:
class Primes:
"""
Represents open-ended, sequential list of prime numbers
starting with 2. Uses trial-by-division generator to append
to list. Maintains current pointer, allows random access
and list slicing syntax (but not from "end of list").
Given simple trial-by-division, this class is suitable for
exploring low primes only.
"""
pr = [2] # class level list of primes
def __init__(self):
self.gen = self.__generator()
self.current = -1
self.max = 0
def __iter__(self):
"""
this object implements iteration
"""
return self
def next(self):
"""
invoke gen (internal lazy evaluator) only if needed
"""
self.current += 1
self.max = max(self.max,self.current)
if self.current > len(Primes.pr)-1:
return self.gen.next()
else:
return Primes.pr[self.current]
def previous(self):
"""
move pointer back one position
"""
self.current -= 1
if self.current < 0:
self.current = 0
return self.pr[self.current]
def first(self):
"""
return to 0th position
"""
self.current = 0
return Primes.pr[self.current]
def last(self):
"""
jump to highest position ever pointed to
by this object
"""
self.current = self.max
return Primes.pr[self.current]
def skip(self,n):
"""
skip n primes (n may be negative, to skip
backward)
"""
# pointer must be >= 0
return self.__getitem__(max(0,self.current + n))
def __getitem__(self,n):
"""
implements syntax object[n] for nth prime
"""
if n<0: raise ValueError,"Out of range"
if n > len(Primes.pr)-1:
self.current = self.max
while n > self.current:
self.next()
else:
self.current = n
self.max = max(self.max,self.current)
return Primes.pr[self.current]
def __getslice__(self,a,b):
rlist = []
if b==2147483647 or a<0 or b<0:
raise ValueError("Unbounded above")
for i in range(a,b):
rlist.append(self.__getitem__(i))
return rlist
def __generator(self):
"""
Iterator for lazy evaluation.
Yield next higher prime, accruing successive primes
in class variable pr (shared by all Prime objects)
Uses trial-by-division, long integers if necessary
"""
i = Primes.pr[-1]
if i==2:
i -= 1
new = 0
while 1:
try:
i += 2
except OverflowError:
i += 2L
if new:
yield Primes.pr[-1]
new = 0
for t in Primes.pr:
if t*t > i:
# if t**2>candidate, we have a new prime
Primes.pr.append(i)
new = 1
break
if i%t == 0:
# test divide by primes so far,
# move to next odd whenever remainder=0
break
Kirby
From urnerk@qwest.net Fri Feb 1 03:45:01 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 31 Jan 2002 19:45:01 -0800
Subject: [Tutor] List of Objects?
In-Reply-To:
[CN] Oak, Foiled & Antique
Furniture
18/12/2001
"""
IDs=re.compile('.*
--------------090205090309040109020501
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Hi @ ALL !
I think i solved my first problem creating a .dll with Visual C++,
because first i choosed only the option "win32 dynamic link library" and
not the "MFC AppWizard". The AppWizard also creates a .def file where
are informations about the Exports from the new .dll file.
But now, after compiling the the whole code, using the AppWizard, the
following Error occurs:
Kompilierung läuft...
simanneal.cpp
c:\arbeit_diplomarbeit\__optimierer\testlauf\bla bla\simanneal.cpp(496)
: fatal error C1010: Unerwartetes Dateiende waehrend der Suche nach der
Direktive fuer die vorkompilierte Header-Datei
simanneal_wrap.cpp
c:\arbeit_diplomarbeit\__optimierer\testlauf\bla
bla\simanneal_wrap.cpp(34) : warning C4005: 'SWIGEXPORT' :
Makro-Neudefinition
c:\arbeit_diplomarbeit\__optimierer\testlauf\bla
bla\simanneal_wrap.cpp(32) : Siehe vorherige Definition von 'SWIGEXPORT'
....
Generieren von Code...
Fehler beim Ausführen von cl.exe.
bla bla.dll - 7 Fehler, 4 Warnung(en)
Perhaps, i have to write additional information in the .def file of the
functions, i want to be exported from the new .dll
Have anyone had this kind of problem ?
Greetings
Marcus
--------------090205090309040109020501
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi @ ALL ![CN] Oak, Foiled & Antique
Furniture
18/12/2001
I think i solved my first problem creating a .dll with Visual C++, because
first i choosed only the option "win32 dynamic link library" and not the
"MFC AppWizard". The AppWizard also creates a .def file where are informations
about the Exports from the new .dll file.
But now, after compiling the the whole code, using the AppWizard, the following
Error occurs:
Kompilierung läuft...
simanneal.cpp
c:\arbeit_diplomarbeit\__optimierer\testlauf\bla bla\simanneal.cpp(496) :
fatal error C1010: Unerwartetes Dateiende waehrend der Suche nach der Direktive
fuer die vorkompilierte Header-Datei
simanneal_wrap.cpp
c:\arbeit_diplomarbeit\__optimierer\testlauf\bla bla\simanneal_wrap.cpp(34)
: warning C4005: 'SWIGEXPORT' : Makro-Neudefinition
c:\arbeit_diplomarbeit\__optimierer\testlauf\bla bla\simanneal_wrap.cpp(32)
: Siehe vorherige Definition von 'SWIGEXPORT'
....
Generieren von Code...
Fehler beim Ausführen von cl.exe.
bla bla.dll - 7 Fehler, 4 Warnung(en)
Perhaps, i have to write additional information in the .def file of the functions,
i want to be exported from the new .dll
Have anyone had this kind of problem ?
Greetings
Marcus
--------------090205090309040109020501--
From csmith@blakeschool.org Fri Feb 1 16:29:50 2002
From: csmith@blakeschool.org (Christopher Smith)
Date: Fri, 01 Feb 2002 10:29:50 -0600
Subject: [Tutor] a bug?
Message-ID:
> href="lead.asp?ItemID=146759">[CN] Oak, Foiled & Antique
> Furniture
> 18/12/2001
>
> """
>
> IDs=re.compile('.* Results=re.findall(IDs,Text)
you call re.findall with a regular expression object as a first parameter
which should be a string. What you want to do is
Results = IDs.findall(Text)
i. e. call the appropriate method on the re object you created.
2.) There are two whitespaces (a space and a newline - the latter may be
inserted by your or my mail agent) between "
Message-ID: <000001c1ac7f$08380e40$5b582144@aberdn01.md.comcast.net>
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]
> On Behalf Of Ciaguy@aol.com
> Sent: Saturday, February 02, 2002 12:35 PM
> To: tutor@python.org
> Subject: [Tutor] Newbie
> I recently bought "SAMS Teach Yourself Python in 24 Hours."
> Hour #2 suggests I sign up for the Tutor mailing list. How to do
this?
Go to http://mail.python.org/mailman/listinfo/tutor and fill out the
form under Subscribing to Tutor. For a newbie to python
http://www.python.org/doc/Newbies.html is a good place to visit. And a
good website to begin using IDLE is
http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/ . When you save a
program just add the .py extension to the name. For example,
firstprogram would be firstprogram.py in python.
> Background: I wish to teach myself to write programs for my
> computer. I have absolutely no experience. I am probably around 10
notches
> below beginner level. I am no math whiz. I am just a 60 y/o male
with only
> a keen desire to teach myself a programming language. Friends(?) have
> suggested I start with XBasic, Liberty Basic, Visual Basic, or even
C++ (Wrong!).
> Will Python be a good "idiot" user friendly language for self
teachers, such
> as myself? Thanks for any advice or input.
> Sincerely,
> Wolf
I am a beginner also, started out with Qbasic and felt that that was a
mistake. A good over all book for me about the concepts of computer
programming is "How Computer Programming Works" by Dan Appleman. And the
book that I like the best for learning python so far is "The Quick
Python Book" by Daryl Harms, even though it is written for people who
have experience programming in another language.
Randy Talbot
From kalle@gnupung.net Sun Feb 3 15:10:08 2002
From: kalle@gnupung.net (Kalle Svensson)
Date: Sun, 3 Feb 2002 16:10:08 +0100
Subject: [Tutor] Newbie
In-Reply-To: <46.21e081ac.298d7d36@aol.com>
References: <46.21e081ac.298d7d36@aol.com>
Message-ID: <20020203151008.GA27583@sandra.lysator.liu.se>
[Ciaguy@aol.com]
> I recently bought "SAMS Teach Yourself Python in 24 Hours." Hour #2
> suggests I sign up for the Tutor mailing list. How to do this?
Visit http://mail.python.org/mailman/listinfo/tutor and follow the
instructions there under "Subscribing to Tutor".
> Background: I wish to teach myself to write programs for my
> computer. I have absolutely no experience. I am probably around 10
> notches below beginner level. I am no math whiz. I am just a 60
> y/o male with only a keen desire to teach myself a programming
> language.
Good! The desire to learn is required, everything on top of that
(like a computer, or a mailing list like this to ask questions) is
added bonus, but not necessary.
[...]
> Will Python be a good "idiot" user friendly language for self
> teachers, such as myself? Thanks for any advice or input.
Python is an excellent choise for a first language. It's remarkably
clear and simple, yet it's powerful enough for writing almost any type
of program. Also, there is a large and friendly user community that
can be of invaluable assistance to a self teacher. Good luck to you,
and don't be afraid to ask questions. The list is here for you!
Peace,
Kalle
--
Kalle Svensson (kalle@gnupung.net) - Laziness, impatience, hubris: Pick two!
English: http://www.gnupung.net/ Svenska: http://www.lysator.liu.se/~kalle/
Stuff: ["http://www.%s.org/" % x for x in "gnu debian python emacs".split()]
From m_konermann@gmx.de Sun Feb 3 16:30:53 2002
From: m_konermann@gmx.de (Keule)
Date: Sun, 03 Feb 2002 17:30:53 +0100
Subject: [Tutor] C++ Extension Problems (Part1)
Message-ID: <3C5D65BD.7060800@gmx.de>
This is a multi-part message in MIME format.
--------------030800020909010209070602
Content-Type: multipart/alternative;
boundary="------------020406090507060503020205"
--------------020406090507060503020205
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Hi @ ALL !
I´ve created a .dll file with SWIG under windows. Now i want to use it
and try to import it into the simannealfile.py modul, but pythonwin
always gives the following error:
File "C:\Python21\Pythonwin\pywin\framework\scriptutils.py" , line 394,
in ImportFile
exec codeObj in __main__.__dict__
File " href="lead.asp?ItemID=146700">[CN] Oak, Foiled & Antique
> Furniture
> 18/12/2001
>
I´ve created a .dll file with SWIG under windows. Now i want to use it and
try to import it into the simannealfile.py modul, but pythonwin always gives
the following error:
File
"C:\Python21\Pythonwin\pywin\framework\scriptutils.py"
, line 394, in ImportFile
exec codeObj in __main__.__dict__
File "<auto import>", line 1, in ?
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
Traceback (most recent call last):
File
"C:\Python21\Pythonwin\pywin\framework\scriptutils.py"
, line 301, in RunScript
exec codeObject in __main__.__dict__
File
"C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile\simannealfile.py"
, line 2, in ?
import simannealfile
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
I checked out the examples ,delivered with SWIG, and compared them with
my Settings under Visual C++. The Examples are all functioned and now i absolutly
did´nt know whats going wrong and why i always get the Errormessage above.
I ´ve put my files with these mail.
Perhaps anyone of you could check my settings an can give me an advice what´s
going wrong.
Thanks a lot
Greetings
Marcus
--------------020406090507060503020205--
--------------030800020909010209070602
Content-Type: text/plain;
name="basisfile.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="basisfile.h"
#ifndef BASISFILE_H
#define BASISFILE_H
#include "safe_string.h"
#include "variable.h"
struct filetext {
filetext ();
~filetext ();
void clean (struct filetext *ft);
void clean ();
struct string text;
struct string parameter_text;
/* text first line number */
int tfln;
/* text last line number */
int tlln;
/* pointer to the variable-struct, which points to this
text-struct. */
struct variablelist *variable_pointer;
struct filetext *next;
};
struct basisfile {
basisfile ();
basisfile (struct string &fn);
basisfile (char *fn);
~basisfile ();
void init (char *fn);
void clean ();
struct filetext *text;
struct string *filename;
int readfile ();
/* write this.text and this.parameter_text to file 'filename'.
writefile walks through from this to last element of next-pointer
and writes first text and then parameter_text to the file. The
file is opened once in mode 'mode'. Values of mode are meant to
be "w"- or "a"-modes according to the fopen()-function. */
int writefile (struct string &filename, char *mode = "w");
int writefile (char *mode = "w");
int build (struct variablelist *variable);
/* searches parameter_text specified in 'variable' in text of
'text'. If found, the text of 'text' is split into 'text' and
'parameter_text' and in case some text of the line is left, a new
node is inserted into 'text'. In case of **text contains a
splitted line, split will call itself recursively in order to
search the whole line. The text-pointer of *variable is set to
the node of **text containing the parametertext belonging to
variable.
How is parameter_text searched for? It is searched for the line
variable->linenumber. variable->preseparator and
variable->pastseparator gives the text left and right from the
searched parameter_text. variable->position gives the number of
preseparator sets which must be found before parameter_text. If
variable->position is 0, variable->preseparator is ignored and it
is assumed, that the parameter_text starts at the beginning of
the line. If enough preseparators are found, the pastseparator
will be searched for. An empty pastseparator will lead to an
error, if the file is continuing after the parameter_text. A
pastseparator not found, too.
Return value is 0, if everything is fine, > 0 if an error occured.
*/
int split (struct filetext **text, struct variablelist *variable,
int separators = 0);
};
/* Copys x_now of variables to their parameter_texts */
int vl2pt (struct variablelist *vl);
void print (struct filetext *ft);
#endif
--------------030800020909010209070602
Content-Type: text/plain;
name="calculate.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="calculate.cpp"
#include "calculate.h"
#include "basisfile.h"
int calculate (struct variable &result, struct variablelist *vl,
struct basisfile *bf, struct string *call) {
/* create basisfile with given values of variables */
/* 1. copy actual variables to parameter text parts */
if (vl2pt (vl)) {
printf ("calculate ():\n ");
printf ("Error while copying variables (x_now) to parameter texts.\n");
return 1;
}
/* 2. write basisfile */
if (bf)
bf->writefile ();
else {
printf ("calculate ():\n No basisfile structure specified.\n");
return 1;
}
/* execute calculation */
call->system_call ();
/* build result out of calculated data */
/* under construction !! */
FILE *ergebnis = fopen ("output.asc", "r");
if (ergebnis)
fscanf(ergebnis, "%lf", &(result.dv));
else {
printf ("calculate: Ausgabedatei `output.asc' nicht gefunden.\n");
return 1;
}
fclose (ergebnis);
return 0;
}
int calculate (struct variable &result, struct basisfile *bf,
struct string *call) {
/* write basisfile */
if (bf)
bf->writefile ();
else {
printf ("calculate ():\n No basisfile structure specified.\n");
return 1;
}
/* execute calculation */
call->system_call ();
/* build result out of calculated data */
/* under construction !! */
FILE *ergebnis = fopen ("output.asc", "r");
if (ergebnis)
fscanf(ergebnis, "%lf", &(result.dv));
else {
printf ("calculate: Ausgabedatei `ergebnis.asc' nicht gefunden.\n");
return 1;
}
fclose (ergebnis);
return 0;
}
--------------030800020909010209070602
Content-Type: text/plain;
name="calculate.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="calculate.h"
#ifndef CALCULATE_H
#define CALCULATE_H
#include "variable.h"
/* calculates results for basisfile. If vl is parameter, the x_now's
from vl will be incorporated into the basisfile. Otherwise not
(this version is needed for first calculations, when x_now is still
empty.) */
int calculate (struct variable &result, struct variablelist *vl,
struct basisfile *bf, struct string *call);
int calculate (struct variable &result, struct basisfile *bf,
struct string *call);
#endif
--------------030800020909010209070602
Content-Type: text/plain;
name="evaluate.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="evaluate.cpp"
#include "evaluate.h"
evaluate::evaluate () {
goal = NULL;
epsilon = NULL;
minchange = NULL;
criteria = '0';
}
evaluate::~evaluate () {
}
int evaluate::abort (struct variable &result) {
int comp;
switch (criteria) {
case 'e': /* epsilon-environment of goal must be reached */
printf ("evaluate::abort(): case 'e' not implemented yet.\n");
return -1;
break;
case 's': /* result must be smaller than goal */
comp = smaller (&result, goal);
if (comp < 0) {
printf ("evaluate::abort():\n");
printf (" Error while comparing result with goal.\n");
return -1;
}
return comp;
break;
case 'g': /* result must be greater than goal */
comp = greater (&result, goal);
if (comp < 0) {
printf ("evaluate::abort():\n");
printf (" Error while comparing result with goal.\n");
return -1;
}
return comp;
break;
case 'n': /* `minchange' has to be exceeded after `n' calculations of
result */
printf ("evaluate::abort(): case 'n' not implemented yet.\n");
return -1;
break;
default:
printf ("evaluate::abort():\n");
printf (" Unknown criteria `%c'.\n");
return -1;
}
return 0;
}
--------------030800020909010209070602
Content-Type: text/plain;
name="evaluate.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="evaluate.h"
#ifndef EVALUATE_H
#define EVALUATE_H
#include "variable.h"
struct evaluate {
evaluate ();
~evaluate ();
/* criteria is used to choose method to determine end or success of
optimization.
'e': epsilon-environment of goal must be reached
's': result must be smaller than goal
'g': result must be greater than goal
'n': `minchange' has to be exceeded after `n' calculations of
result
*/
char criteria;
/* goal of optimization. */
struct variable *goal;
/* error with which goal may be achieved */
struct variable *epsilon;
/* `minchange' has to be exceeded after `n' calculations of result */
struct variable *minchange;
int n;
int abort (struct variable &result);
};
#endif
--------------030800020909010209070602
Content-Type: text/plain;
name="safe_string.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="safe_string.h"
#ifndef SAFE_STRING_H
#define SAFE_STRING_H
#include
--------------030800020909010209070602
Content-Type: text/plain;
name="simannealfile.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="simannealfile.py"
#import string,re,sys,glob,operator
import simannealfile
#instance1=simannealfile.simulated_annealing
#print 'test=',instance1
--------------030800020909010209070602
Content-Type: text/plain;
name="variable.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="variable.cpp"
#include "variable.h"
#include "basisfile.h"
variable::variable () {
sv = NULL;
dprecision = 6;
type = '0';
}
variable::variable (char t) {
init (t);
}
variable::variable (double d, int prec) {
init (d, prec);
}
variable::variable (int i) {
init (i);
}
variable::variable (struct string &s) {
init (s);
}
variable::~variable () {
}
void variable::init (char t) {
type = t;
sv = NULL;
}
void variable::init (double d, int prec) {
sv = NULL;
dv = d;
dprecision = prec;
type = 'd';
}
void variable::init (int i) {
sv = NULL;
iv = i;
type = 'i';
}
void variable::init (struct string &s) {
sv = new struct string;
sv->copy (s);
type = 's';
}
struct variable &variable::operator= (struct variable &v) {
(*this).type = v.type;
switch (v.type) {
case 'd':
(*this).dv = v.dv;
(*this).dprecision = v.dprecision;
break;
case 'i':
(*this).iv = v.iv;
break;
case 's':
(*this).sv = new struct string;
(*this).sv->copy (*(v.sv));
break;
default:
printf ("&variable::operator= (struct variable &v):\n ");
printf ("Unknown type `%c'.\n", v.type);
exit (1);
break;
}
return *this;
}
int variable::copy (struct string &s) {
char *str;
s.out (&str);
switch (type) {
case 'd' : /* double value */
if (!sscanf(str, "%lf", &dv)) {
printf ("variable::copy (struct string &s):\n ");
printf ("Error while reading double value in from string:\n ");
strprint (s, "`", "'\n");
return 1;
}
break;
case 'i' : /* integer value */
if (!sscanf(str, "%d", &dv)) {
printf ("variable::copy (struct string &s):\n ");
printf ("Error while reading integer value in from string:\n ");
strprint (s, "`", "'\n");
return 1;
}
break;
break;
case 's' : /* string value */
sv = new struct string (s);
break;
default :
printf ("variable::copy (struct string &s):\n ");
printf ("Unknown type of variable `%c'.\n", type);
return 1;
}
return 0;
}
simanneal_parameter::simanneal_parameter () {
dx = NULL;
}
simanneal_parameter::~simanneal_parameter () {
if (dx) {
delete dx;
dx = NULL;
}
}
variablelist::variablelist () {
next = NULL;
text = NULL;
x_now = NULL;
x_opt = NULL;
x_min = NULL;
x_max = NULL;
sap = NULL;
}
variablelist::~variablelist () {
clean ();
}
void variablelist::clean () {
clean (this);
}
void variablelist::clean (struct variablelist *vl) {
if (vl) {
if (vl->next) {
clean (vl->next);
vl->next = NULL;
}
preseparator.clean ();
pastseparator.clean ();
if (x_opt) {
delete x_opt;
x_opt = NULL;
}
if (x_now) {
delete x_now;
x_now = NULL;
}
if (x_min) {
delete x_min;
x_min = NULL;
}
if (x_max) {
delete x_max;
x_max = NULL;
}
if (text) {
delete text;
text = NULL;
}
if (sap) {
delete sap;
sap = NULL;
}
}
}
int variablelist::pt2xn (int n) {
int i=0;
struct variablelist *help = this;
while (help && iErstellungsprotokoll
--------------------Konfiguration: simannealfile - Win32 Debug--------------------
Befehlszeilen
Erstellen der temporären Datei "C:\DOKUME~1\MKONER~1\LOKALE~1\Temp\RSP137.bat" mit Inhalten
[
@echo off
echo In order to function correctly, please ensure the following environment variables are correctly set:
echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
echo PYTHON_LIB: %PYTHON_LIB%
echo on
swig -python -c++ -o .\simannealfile_wrap.cpp .\simannealfile.i
]
Erstellen der Befehlzeile "C:\DOKUME~1\MKONER~1\LOKALE~1\Temp\RSP137.bat"
Erstellen der temporären Datei "C:\DOKUME~1\MKONER~1\LOKALE~1\Temp\RSP138.tmp" mit Inhalten
[
/nologo /MTd /W3 /GX /Od /I "c:\python21\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SIMANNEALFILE_EXPORTS" /Fp"Debug/simannealfile.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
"C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile\basisfile.cpp"
"C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile\calculate.cpp"
"C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile\evaluate.cpp"
"C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile\safe_string.cpp"
"C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile\simannealfile.cpp"
"C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile\simannealfile_wrap.cpp"
"C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile\variable.cpp"
]
Creating command line "cl.exe @C:\DOKUME~1\MKONER~1\LOKALE~1\Temp\RSP138.tmp"
SWIG Routine
In order to function correctly, please ensure the following environment variables are correctly set:
PYTHON_INCLUDE: c:\python21\include
PYTHON_LIB: c:\python21\libs\python21.lib
C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile>swig -python -c++ -o .\simannealfile_wrap.cpp .\simannealfile.i
Erstellen der temporären Datei "C:\DOKUME~1\MKONER~1\LOKALE~1\Temp\RSP139.tmp" mit Inhalten
[
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib c:\python21\libs\python21.lib /nologo /dll /incremental:no /pdb:"Debug/simannealfile.pdb" /machine:I386 /out:"simannealfile.dll" /implib:"Debug/simannealfile.lib" /libpath:"C:\Python21\libs"
.\Debug\basisfile.obj
.\Debug\calculate.obj
.\Debug\evaluate.obj
.\Debug\safe_string.obj
.\Debug\simannealfile.obj
.\Debug\simannealfile_wrap.obj
.\Debug\variable.obj
]
Erstellen der Befehlzeile "link.exe @C:\DOKUME~1\MKONER~1\LOKALE~1\Temp\RSP139.tmp"
Ausgabefenster
Kompilierung läuft...
basisfile.cpp
calculate.cpp
evaluate.cpp
safe_string.cpp
simannealfile.cpp
simannealfile_wrap.cpp
variable.cpp
Linker-Vorgang läuft...
Bibliothek Debug/simannealfile.lib und Objekt Debug/simannealfile.exp wird erstellt
Ergebnisse
simannealfile.dll - 0 Fehler, 0 Warnung(en)
tempetature =3D input("What is the temperature of the =
spam?")
print "The salad is =
properly=20
cooked"
else:
print "Cook the salad some=20
more"
I´ve created a .dll file with SWIG under windows. Now i want to use it and
try to import it into the simannealfile.py modul, but pythonwin always gives
the following error:
File "C:\Python21\Pythonwin\pywin\framework\scriptutils.py", line 394,
in ImportFile
exec codeObj in __main__.__dict__
File "<auto import>", line 1, in ?
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
Traceback (most recent call last):
File "C:\Python21\Pythonwin\pywin\framework\scriptutils.py", line 301,
in RunScript
exec codeObject in __main__.__dict__
File "C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile\simannealfile.py",
line 2, in ?
import simannealfile
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
I checked out the examples ,delivered with SWIG, and compared them with my
Settings under Visual C++. The Examples are all functioned and now i absolutly
did´nt know whats going wrong and why i always get the Errormessage above.
I ´ve put my files with these mail.
Perhaps anyone of you could check my settings an can give me an advice what´s
going wrong.
Thanks a lot
Greetings
Marcus
--------------000502040303080901030702--
--------------090302080802010307050504
Content-Type: text/plain;
name="basisfile.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="basisfile.cpp"
#include "basisfile.h"
filetext::filetext () {
tlln = 0;
tfln = 0;
variable_pointer = NULL;
next = NULL;
}
filetext::~filetext () {
clean ();
}
void filetext::clean () {
clean (this);
}
void filetext::clean (struct filetext *ft) {
if (ft) {
if (ft->next) {
clean (ft->next);
ft->next = NULL;
}
variable_pointer = NULL;
text.clean ();
parameter_text.clean ();
}
}
basisfile::basisfile () {
filename = NULL;
text = NULL;
}
basisfile::basisfile (struct string &fn) {
filename = new struct string;
filename->copy (fn);
text = NULL;
}
basisfile::basisfile (char *fn) {
init (fn);
}
basisfile::~basisfile () {
clean ();
}
void basisfile::init (char *fn) {
filename = new struct string;
filename->copy (fn);
text = NULL;
}
void basisfile::clean () {
if (filename) {
delete filename;
filename = NULL;
}
if (text) {
delete text;
text = NULL;
}
}
int basisfile::readfile () {
if (!filename->size) {
printf ("basisfile::readfile:\n No filename to read specified.\n");
return 1;
}
/* initialize text-pointer */
text = new struct filetext;
/* Copy complete input file to text */
text->tfln = 1;
if ((text->tlln = text->text.filereadc (*filename, '\n')) < 0) {
printf ("basisfile::readfile ():\n ");
strprint (*filename, "Error while reading file `", "'.\n");
return 1;
}
return 0;
}
int basisfile::writefile (string &otherfilename, char *mode) {
struct filetext *help = this->text;
if ( (*mode != 'a') && (*mode != 'w') ) {
printf ("basisfile::writefile:\n Invalid mode %s ", mode);
strprint (otherfilename, "for writing to file `", "'.\n");
return 1;
}
FILE *out = otherfilename.fileopen (mode);
if (out)
while (help != NULL) {
if (help->text.size)
help->text.filewrite (out);
if (help->parameter_text.size)
help->parameter_text.filewrite (out);
help = help->next;
}
else {
strprint (otherfilename, "basisfile::writefile:\n Unable to open file `",
"'");
printf (" with mode %s.\n", mode);
return 2;
}
while (help != NULL) {
if (help->text.size)
help->text.filewrite (otherfilename, "a");
if (help->parameter_text.size)
help->parameter_text.filewrite (otherfilename, "a");
help = help->next;
}
return 0;
}
int basisfile::writefile (char *mode) {
struct filetext *help = this->text;
if ( (*mode != 'a') && (*mode != 'w') ) {
printf ("basisfile::writefile:\n Invalid mode %s ", mode);
strprint (*filename, "for writing to file `", "'.\n");
return 1;
}
FILE *out = filename->fileopen (mode);
if (out) {
while (help != NULL) {
if (help->text.size)
help->text.filewrite (out);
if (help->parameter_text.size)
help->parameter_text.filewrite (out);
help = help->next;
}
fclose (out);
}
else {
strprint (*filename, "basisfile::writefile:\n Unable to open file `", "'");
printf (" with mode %s.\n", mode);
return 2;
}
// while (help != NULL) {
// if (help->text.size)
// help->text.filewrite (*filename, "a");
// if (help->parameter_text.size)
// help->parameter_text.filewrite (*filename, "a");
// help = help->next;
// }
return 0;
}
int basisfile::build (struct variablelist *variable) {
struct filetext *help;
/* Look for specified variable */
while (variable) {
help = this->text;
/* search all parts of basisfile (except in parameter-text-parts) */
while (help) {
/* search in text */
if (variable->linenumber <= help->tlln) {
/* split text */
if ( split (&help, variable) ) {
printf ("Error while splitting basisfile structure.\n");
return 1;
}
else
/* parameter found */
help = NULL;
}
else {
/* nothing found */
help = help->next;
}
}
/* found parameter? */
if (!variable->text) {
printf ("Couldn't find parameter number %d.\n", variable->number);
printf ("Probably line number %d exceeds number of lines of file.\n",
variable->linenumber);
return 2;
}
/* look at next one */
variable = variable->next;
}
return 0;
}
int basisfile::split (struct filetext **text, struct variablelist *variable,
int separators) {
int line = (*text)->tfln;
int linepos = 0, prepos = 0, pastpos;
int original_size = (*text)->text.size;
int original_tlln = (*text)->tlln;
string help, dummy;
int next_line_offset;
struct filetext *hft = NULL;
/* check text */
if (!text || !(*text)) {
printf ("basisfile::split:\n Empty filetext structure. Aborting.\n");
return 100;
}
/* check linenumber and position */
if (variable->linenumber < 1) {
printf ("basisfile::split:\n Invalid linenumber %d.\n",
variable->linenumber);
return 99;
}
if (variable->position < 0) {
printf ("basisfile::split:\n Invalid position %d.\n",
variable->position);
return 99;
}
/* find right line */
while (line < variable->linenumber) {
linepos += (*text)->text.string_complement_span("\n", linepos) + 1;
line++;
}
next_line_offset = (*text)->text.string_complement_span("\n", linepos) + 1;
/* if "\n" was not found, next_line_offset is position of "\0".
Since this character is not meant to be copied to help, we must
decrease next_line_offset by 1 in this case. */
if (next_line_offset+linepos == (*text)->text.size)
help.ncopy ((*text)->text, next_line_offset-1, linepos);
else
help.ncopy ((*text)->text, next_line_offset, linepos);
/* find beginning position of parameter-text in line */
while (separators < variable->position) {
/* if not found */
if (!(help.string_string(dummy, variable->preseparator, prepos+1))) {
/* Does line in question continue with next struct? */
if ( ((*text)->next) && ((*text)->next->tfln == line) )
return (split ( &((*text)->next), variable, separators));
else {
printf("Problem in line no. %d:\n", line);
printf(" Can not find more than %d", separators);
strprint (variable->preseparator, " preseparators `", "'.\n");
printf(" Should have found %d.\n", variable->position);
strprint (help, "Text of the line under consideration:\n \"", "\"\n");
return 1;
}
}
prepos = help.size - dummy.size;
separators++;
}
/* if no separators were meant to be found, dummy would not contain
the string continuing with guessed variable-text start: dummy
would be empty. */
if (!separators)
dummy.copy (help);
/* find ending position of parameter-text in line */
if (!variable->pastseparator.size) {
printf("Problem with specification of variable no. %d:\n",
variable->number);
printf(" pastseparatpor is empty.\n");
return 2;
}
else
if (!(help.string_string(dummy, variable->pastseparator,
help.size-dummy.size
+ variable->preseparator.size - 1))) {
printf("Problem in line no. %d:\n", line);
printf(" Can not find");
strprint (variable->pastseparator, " pastseparator `", "' after ");
printf ("%d. ", separators);
strprint(variable->preseparator, "presaparator `", "'.\n");
strprint (help, "Text of the line under consideration:\n \"", "\"\n");
return 3;
}
pastpos = linepos + help.size - dummy.size;
/* set adequat positions of beginning of parameter_text */
prepos += linepos + variable->preseparator.size - 1;
/* save whole text */
dummy.copy ((*text)->text);
/* copy non-parameter-text to text */
(*text)->text.ncopy (dummy, prepos);
/* breaking line no. $line means, that text last line number is $line now. */
(*text)->tlln = line;
/* Are we dealing with a line already splitted into text and
paramter_text? Then save parameter_text and variable_pointer and
take care of the variable-pointer to this old parameter_text. */
if ((*text)->parameter_text.size) {
/* create new basisfile-node */
hft = new struct filetext;
/* save parameter_text there. */
hft->parameter_text.copy ((*text)->parameter_text);
/* save variable_pointer, too */
hft->variable_pointer = (*text)->variable_pointer;
/* redirect variablelist-pointer to new location of old parameter_text. */
hft->variable_pointer->text = hft;
}
/* is some original text left behind new parameter_text? Save it! */
if (pastpos < original_size) {
/* create new basisfile-node, if not done already */
if (!hft)
hft = new struct filetext;
/* save rest of the text in new node, too */
hft->text.ncopy (dummy, original_size-pastpos-1, pastpos);
}
/* copy parameter-text to parameter_text */
(*text)->parameter_text.ncopy (dummy, pastpos-prepos, prepos);
/* link pointer of variable to according parameter_text and backlink
pointer of *text to that same variable pointer. */
variable->text = (*text);
(*text)->variable_pointer = variable;
/* set adequat line numbers for new node and link it to the
structure, if new node exists. */
if (hft) {
/* text last line number is last line number of original text. */
hft->tlln = original_tlln;
/* if parameter_text does not include '\n' of original line, new
text first line number is just the number of the breaked line
($line). Otherwise new tfln is number of next line. */
if ((*text)->parameter_text.string_character ('\n'))
hft->tfln = line+1;
else
hft->tfln = line;
/* link new node to structure. aehm?? Take care of pointer of variable
struct pointing to text->next. */
hft->next = (*text)->next;
//hbf->next->variable_pointer->text = &hbf;
(*text)->next = hft;
}
return 0;
}
int vl2pt (struct variablelist *vl) {
while (vl) {
if (vl->text) {
if (vl->text->parameter_text.copy (vl->x_now)) {
printf ("vl2pt:\n ");
printf ("Error while copying x_now to paramter text.\n");
return 1;
}
}
else {
printf ("vl2pt:\n ");
printf ("Cannot find paramter text for variable no. %d.\n",
vl->number);
return 2;
}
vl = vl->next;
}
return 0;
}
void print (struct filetext *ft) {
while (ft) {
printf ("tfln = %d\ttlln = %d\n", ft->tfln, ft->tlln);
printf ("variablen_pointer->nummer = ");
if (ft->variable_pointer)
printf("%d\n", ft->variable_pointer->number);
else
printf("\n");
strprint (ft->text, "text:\n `", "'\n");
strprint (ft->parameter_text, "parameter_text: `", "'\n");
ft = ft->next;
}
}
--------------090302080802010307050504
Content-Type: text/plain;
name="basisfile.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="basisfile.h"
#ifndef BASISFILE_H
#define BASISFILE_H
#include "safe_string.h"
#include "variable.h"
struct filetext {
filetext ();
~filetext ();
void clean (struct filetext *ft);
void clean ();
struct string text;
struct string parameter_text;
/* text first line number */
int tfln;
/* text last line number */
int tlln;
/* pointer to the variable-struct, which points to this
text-struct. */
struct variablelist *variable_pointer;
struct filetext *next;
};
struct basisfile {
basisfile ();
basisfile (struct string &fn);
basisfile (char *fn);
~basisfile ();
void init (char *fn);
void clean ();
struct filetext *text;
struct string *filename;
int readfile ();
/* write this.text and this.parameter_text to file 'filename'.
writefile walks through from this to last element of next-pointer
and writes first text and then parameter_text to the file. The
file is opened once in mode 'mode'. Values of mode are meant to
be "w"- or "a"-modes according to the fopen()-function. */
int writefile (struct string &filename, char *mode = "w");
int writefile (char *mode = "w");
int build (struct variablelist *variable);
/* searches parameter_text specified in 'variable' in text of
'text'. If found, the text of 'text' is split into 'text' and
'parameter_text' and in case some text of the line is left, a new
node is inserted into 'text'. In case of **text contains a
splitted line, split will call itself recursively in order to
search the whole line. The text-pointer of *variable is set to
the node of **text containing the parametertext belonging to
variable.
How is parameter_text searched for? It is searched for the line
variable->linenumber. variable->preseparator and
variable->pastseparator gives the text left and right from the
searched parameter_text. variable->position gives the number of
preseparator sets which must be found before parameter_text. If
variable->position is 0, variable->preseparator is ignored and it
is assumed, that the parameter_text starts at the beginning of
the line. If enough preseparators are found, the pastseparator
will be searched for. An empty pastseparator will lead to an
error, if the file is continuing after the parameter_text. A
pastseparator not found, too.
Return value is 0, if everything is fine, > 0 if an error occured.
*/
int split (struct filetext **text, struct variablelist *variable,
int separators = 0);
};
/* Copys x_now of variables to their parameter_texts */
int vl2pt (struct variablelist *vl);
void print (struct filetext *ft);
#endif
--------------090302080802010307050504
Content-Type: text/plain;
name="calculate.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="calculate.cpp"
#include "calculate.h"
#include "basisfile.h"
int calculate (struct variable &result, struct variablelist *vl,
struct basisfile *bf, struct string *call) {
/* create basisfile with given values of variables */
/* 1. copy actual variables to parameter text parts */
if (vl2pt (vl)) {
printf ("calculate ():\n ");
printf ("Error while copying variables (x_now) to parameter texts.\n");
return 1;
}
/* 2. write basisfile */
if (bf)
bf->writefile ();
else {
printf ("calculate ():\n No basisfile structure specified.\n");
return 1;
}
/* execute calculation */
call->system_call ();
/* build result out of calculated data */
/* under construction !! */
FILE *ergebnis = fopen ("output.asc", "r");
if (ergebnis)
fscanf(ergebnis, "%lf", &(result.dv));
else {
printf ("calculate: Ausgabedatei `output.asc' nicht gefunden.\n");
return 1;
}
fclose (ergebnis);
return 0;
}
int calculate (struct variable &result, struct basisfile *bf,
struct string *call) {
/* write basisfile */
if (bf)
bf->writefile ();
else {
printf ("calculate ():\n No basisfile structure specified.\n");
return 1;
}
/* execute calculation */
call->system_call ();
/* build result out of calculated data */
/* under construction !! */
FILE *ergebnis = fopen ("output.asc", "r");
if (ergebnis)
fscanf(ergebnis, "%lf", &(result.dv));
else {
printf ("calculate: Ausgabedatei `ergebnis.asc' nicht gefunden.\n");
return 1;
}
fclose (ergebnis);
return 0;
}
--------------090302080802010307050504
Content-Type: text/plain;
name="calculate.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="calculate.h"
#ifndef CALCULATE_H
#define CALCULATE_H
#include "variable.h"
/* calculates results for basisfile. If vl is parameter, the x_now's
from vl will be incorporated into the basisfile. Otherwise not
(this version is needed for first calculations, when x_now is still
empty.) */
int calculate (struct variable &result, struct variablelist *vl,
struct basisfile *bf, struct string *call);
int calculate (struct variable &result, struct basisfile *bf,
struct string *call);
#endif
--------------090302080802010307050504
Content-Type: text/plain;
name="evaluate.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="evaluate.cpp"
#include "evaluate.h"
evaluate::evaluate () {
goal = NULL;
epsilon = NULL;
minchange = NULL;
criteria = '0';
}
evaluate::~evaluate () {
}
int evaluate::abort (struct variable &result) {
int comp;
switch (criteria) {
case 'e': /* epsilon-environment of goal must be reached */
printf ("evaluate::abort(): case 'e' not implemented yet.\n");
return -1;
break;
case 's': /* result must be smaller than goal */
comp = smaller (&result, goal);
if (comp < 0) {
printf ("evaluate::abort():\n");
printf (" Error while comparing result with goal.\n");
return -1;
}
return comp;
break;
case 'g': /* result must be greater than goal */
comp = greater (&result, goal);
if (comp < 0) {
printf ("evaluate::abort():\n");
printf (" Error while comparing result with goal.\n");
return -1;
}
return comp;
break;
case 'n': /* `minchange' has to be exceeded after `n' calculations of
result */
printf ("evaluate::abort(): case 'n' not implemented yet.\n");
return -1;
break;
default:
printf ("evaluate::abort():\n");
printf (" Unknown criteria `%c'.\n");
return -1;
}
return 0;
}
--------------090302080802010307050504
Content-Type: text/plain;
name="evaluate.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="evaluate.h"
#ifndef EVALUATE_H
#define EVALUATE_H
#include "variable.h"
struct evaluate {
evaluate ();
~evaluate ();
/* criteria is used to choose method to determine end or success of
optimization.
'e': epsilon-environment of goal must be reached
's': result must be smaller than goal
'g': result must be greater than goal
'n': `minchange' has to be exceeded after `n' calculations of
result
*/
char criteria;
/* goal of optimization. */
struct variable *goal;
/* error with which goal may be achieved */
struct variable *epsilon;
/* `minchange' has to be exceeded after `n' calculations of result */
struct variable *minchange;
int n;
int abort (struct variable &result);
};
#endif
--------------090302080802010307050504
Content-Type: text/plain;
name="safe_string.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="safe_string.cpp"
#include "safe_string.h"
#include "variable.h"
#include
--------------090302080802010307050504
Content-Type: text/plain;
name="simannealfile.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="simannealfile.py"
#import string,re,sys,glob,operator
import simannealfile
#instance1=simannealfile.simulated_annealing
#print 'test=',instance1
--------------090302080802010307050504
Content-Type: text/plain;
name="simannealfile_wrap.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="simannealfile_wrap.cpp"
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 1.3.9u-20010926-0849
*
* This file is not intended to be easily readable and contains a number of
* coding conventions designed to improve portability and efficiency. Do not make
* changes to this file unless you know what you are doing--modify the SWIG
* interface file instead.
* ----------------------------------------------------------------------------- */
#define SWIGPYTHON
/***********************************************************************
* common.swg
*
* This file contains generic SWIG runtime support for pointer
* type checking as well as a few commonly used macros to control
* external linkage.
*
* Author : David Beazley (beazley@cs.uchicago.edu)
*
* Copyright (c) 1999-2000, The University of Chicago
*
* This file may be freely redistributed without license or fee provided
* this copyright message remains intact.
************************************************************************/
#include Erstellungsprotokoll
--------------------Konfiguration: simannealfile - Win32 Debug--------------------
Befehlszeilen
Erstellen der temporären Datei "C:\DOKUME~1\MKONER~1\LOKALE~1\Temp\RSP137.bat" mit Inhalten
[
@echo off
echo In order to function correctly, please ensure the following environment variables are correctly set:
echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
echo PYTHON_LIB: %PYTHON_LIB%
echo on
swig -python -c++ -o .\simannealfile_wrap.cpp .\simannealfile.i
]
Erstellen der Befehlzeile "C:\DOKUME~1\MKONER~1\LOKALE~1\Temp\RSP137.bat"
Erstellen der temporären Datei "C:\DOKUME~1\MKONER~1\LOKALE~1\Temp\RSP138.tmp" mit Inhalten
[
/nologo /MTd /W3 /GX /Od /I "c:\python21\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SIMANNEALFILE_EXPORTS" /Fp"Debug/simannealfile.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
"C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile\basisfile.cpp"
"C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile\calculate.cpp"
"C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile\evaluate.cpp"
"C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile\safe_string.cpp"
"C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile\simannealfile.cpp"
"C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile\simannealfile_wrap.cpp"
"C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile\variable.cpp"
]
Creating command line "cl.exe @C:\DOKUME~1\MKONER~1\LOKALE~1\Temp\RSP138.tmp"
SWIG Routine
In order to function correctly, please ensure the following environment variables are correctly set:
PYTHON_INCLUDE: c:\python21\include
PYTHON_LIB: c:\python21\libs\python21.lib
C:\Arbeit_Diplomarbeit\__Optimierer\TEM\simannealfile>swig -python -c++ -o .\simannealfile_wrap.cpp .\simannealfile.i
Erstellen der temporären Datei "C:\DOKUME~1\MKONER~1\LOKALE~1\Temp\RSP139.tmp" mit Inhalten
[
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib c:\python21\libs\python21.lib /nologo /dll /incremental:no /pdb:"Debug/simannealfile.pdb" /machine:I386 /out:"simannealfile.dll" /implib:"Debug/simannealfile.lib" /libpath:"C:\Python21\libs"
.\Debug\basisfile.obj
.\Debug\calculate.obj
.\Debug\evaluate.obj
.\Debug\safe_string.obj
.\Debug\simannealfile.obj
.\Debug\simannealfile_wrap.obj
.\Debug\variable.obj
]
Erstellen der Befehlzeile "link.exe @C:\DOKUME~1\MKONER~1\LOKALE~1\Temp\RSP139.tmp"
Ausgabefenster
Kompilierung läuft...
basisfile.cpp
calculate.cpp
evaluate.cpp
safe_string.cpp
simannealfile.cpp
simannealfile_wrap.cpp
variable.cpp
Linker-Vorgang läuft...
Bibliothek Debug/simannealfile.lib und Objekt Debug/simannealfile.exp wird erstellt
Ergebnisse
simannealfile.dll - 0 Fehler, 0 Warnung(en)
Get=
more from the Web. FREE MSN Explorer download : http://explorer.msn.com