资源简介
C语言-遗传算法的排课源码,遗传算法、使用c语言开发,源码
代码片段和文件信息
#!/usr/bin/python
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License or any later version.
#
# This program is distributed in the hope that it will be useful
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#Received from Vimal Joseph on 7 June 2004
import xml.parsers.expat sys
class Myxml:
Parser = ““
timetable={}
day=““
hour=““
hours=[]
days=[]
which_tt=““
# Prepare for parsing
def __init__(self xml_filename):
assert xml_filename != ““
self.xml_filename = xml_filename
self.Parser = xml.parsers.expat.ParserCreate( )
self.Parser.CharacterDataHandler = self.handleCharData
self.Parser.StartElementHandler = self.handleStartElement
self.Parser.EndElementHandler = self.handleEndElement
# Parse the xml file
def parse(self):
try:
xml_file = open(self.xml_filename “r“)
except:
print “ERROR: Can‘t open xml file %s“%self.xml_filename
raise
else:
try: self.Parser.ParseFile(xml_file)
finally: xml_file.close( )
# to be overridden by implementation-specific methods
def handleCharData(self data): pass
def handleStartElement(self name attrs):
if (name==“Students_Timetable“) or (name==“Teachers_Timetable“):
self.which_tt=name
print “\\documentclass[a4paper12pt]{article}“
print “\\usepackage{anysize}“
print “\\marginsize{1in}{1in}{1in}{1in}“
print “\\begin{document}“
if (name==“Subgroup“) and (self.which_tt==“Students_Timetable“):
self.timetable[“class“]=attrs[‘name‘]
self.days=[]
if (name==“Teacher“) and (self.which_tt==“Teachers_Timetable“):
self.timetable[“teacher“]=attrs[‘name‘]
self.days=[]
if name==“Day“ :
self.day=attrs[‘name‘]
self.days.append(self.day)
self.hours=[]
if name==“Hour“ :
self.hour=attrs[‘name‘]
self.hours.append(self.hour)
if name==“Subject“ :
self.timetable[self.day+self.hour]=attrs[‘name‘]
if name==“Students“ :
self.timetable[self.day+self.hour]=attrs[‘name‘]
def handleEndElement(self name):
if (name==“Subgroup“) and (self.which_tt==“Students_Timetable“):
print “\\begin{tabular}{|c|“
for i in self.days:
print “c|“
print “}“
print “\\hline“
print “\\multicolumn{“len(self.days)+1“}{|c|}{“ self.timetable[“class“]“}\\\\“
print
- 上一篇:即时检测USB设备插拔
- 下一篇:用C++求龙贝格积分
评论
共有 条评论