Files
platz/libs/platz.py
T
Michael Stangl 6e3649ed27 Port codebase from Python 2 to Python 3
Replace Python 2-only constructs throughout libs/: print statements,
ConfigParser -> configparser, sets.Set -> builtin set, string.split ->
str.split, xrange -> range, dict.has_key()/.iteritems() -> in/.items(),
old-style raise Exception, "msg" syntax, and __cmp__ -> __eq__/__lt__
via functools.total_ordering (Python 3 dropped cmp()/__cmp__, which
max()/.sort() rely on). Also cleaned up mixed tab/space indentation
that Python 3's stricter tokenizer rejects.

Fixed two latent bugs that only surfaced once end-to-end runs were
possible under Python 3's stricter error handling:
- HandleBestellung() compared G.Anzahl (a bound method) to an int
  instead of calling G.Anzahl() - silently "worked" under Python 2's
  permissive cross-type ordering, raises TypeError under Python 3.
- LeuteAllein() raised KeyError for VIP-group members, who are never
  added to the regular Gruppen container; now skips people with no
  group entry instead of crashing.

Verified end-to-end: bin/platz.sh --indir work/test1 and --indir
work/test2 (VIP group included) both run to completion and produce
correctly formatted output.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-09 12:27:27 +02:00

85 lines
2.3 KiB
Python
Executable File

"""
Enthaelt alle Datenstrukturen um die Sitzplatzverteilung als GA zu variieren
"""
__author__ = "Michael Stangl"
__version__ = "$Revision: $"
__date__ = "$Date: $"
__copyright__ = "Copyright (c) 2005 Michael Stangl"
__license__ = "Python"
from ga import *
from Strukturdaten import *
import configparser
import optparse
if __name__ == '__main__':
# Kommandozeilenoption --indir: Verzeichnis mit den Eingabedateien
# (tische.ini, bestellung.xml) und Ziel fuer die Ausgabedateien
# (TischePersonen.txt, PersonenTische.csv)
parser = optparse.OptionParser()
parser.add_option( "--indir", dest="indir", default=None,
help="Verzeichnis mit tische.ini und bestellung.xml; "
"dort werden auch TischePersonen.txt und PersonenTische.csv abgelegt" )
(options, args) = parser.parse_args()
if options.indir is None:
parser.error( "--indir ist erforderlich" )
InDir = os.path.expandvars( os.path.expanduser( options.indir ) )
if not os.path.isdir( InDir ):
parser.error( "--indir '%s' ist kein Verzeichnis" % InDir )
# lade Vorgaben fuer Optimierungszyklus und
config = configparser.ConfigParser()
ConfigPath= os.path.join( os.getenv('PLATZ_CFG'), 'platz.cfg')
config.read( os.path.expandvars( ConfigPath ))
Zyklusconfig = os.path.normpath( config.get( 'Config', 'Zyklusdatei' ))
Zyklusconfig = os.path.expandvars( Zyklusconfig )
Zyklusart = config.get( 'Config', 'Zyklusart' )
Strafenconfig = os.path.normpath(config.get( 'Config', 'Strafendatei' ))
Strafenconfig = os.path.expandvars( Strafenconfig )
## print Strafenconfig
# lade Eingabedateien
Tischconfig = os.path.join( InDir, 'tische.ini' )
Bestellung = os.path.join( InDir, 'bestellung.xml' )
# lade Ausgabedateien
AusgabeTP= os.path.join( InDir, 'TischePersonen.txt' )
AusgabePT = os.path.join( InDir, 'PersonenTische.csv' )
Z = Zyklus()
Z.laden( Zyklusconfig, Zyklusart )
print(Z)
SL = Strafliste()
SL.laden( Strafenconfig )
print(SL)
TE = Tische()
TE.laden( Tischconfig )
print(TE)
InputFile = XMLConfig()
[ PN, GN, VIPGruppe, VIPListePT ] = InputFile.laden( Bestellung )
print(PN)
print(GN)
print(VIPGruppe)
print(VIPListePT)
print("\n-- Erzeuge Farm:")
F1 = Farm( Z, Sitzplatzverteilung, Tische=TE, Gruppen=GN, Strafen=SL, VIPListe=VIPListePT, VIPs=VIPGruppe )
#print(F1)
S = F1.Bester()
print(S)
S.speichern( AusgabeTP, AusgabePT )
else:
pass