def main(file): lines=[] '''with fileinput.input(files=(file)) as f: for line in f: lines.append(line) ''' finp=fileinput.input(files=(sys.argv[2])) for line in finp: lines.append(line) circuits=hw2.buildCircuits(lines) elements=hw2.getElements(circuits) connMatrix=hw2.buildConnMatrix(circuits,elements) for line in hw5.hamiltonChain(connMatrix,elements): print(line)
def main(file): lines = [] '''with fileinput.input(files=(file)) as f: for line in f: lines.append(line) ''' finp = fileinput.input(files=(sys.argv[2])) for line in finp: lines.append(line) circuits = hw2.buildCircuits(lines) elements = hw2.getElements(circuits) connMatrix = hw2.buildConnMatrix(circuits, elements) for line in hw5.hamiltonChain(connMatrix, elements): print(line)
def result(self, data=None): if not data: return self.header + '''Введите <a href="/hw5">данные</a>''' + self.footer circuits = hw2.buildCircuits(data.split('\n')) elements = set() html = '''<b>Исходные данные</b><br /><br />''' for i in range(1, len(circuits) + 1): if len(circuits[i]) <= 1: del circuits[i] html += 'Цепь №%i пустая <br />' % i continue html += 'Цепь №%i %s<br />' % (i, str(circuits[i])) for el in circuits[i]: elements.add(el) elements = list(elements) elements.sort() matrix1 = hw2.buildComplexMatrix(circuits, elements) width = int(100 / (len(circuits) + 1)) html += '''<br /> <b>Матрица комплексов</b><br /><br /> <table cellspacing="0"> <tr class="gray"> <td width="%i%%" class="white"> </td> ''' % width for key in circuits: html += '<td width="%i%%"><b>%i</b></td>\n' % (width, key) html += '</tr>\n' lgray = False i = 0 for row in matrix1: if lgray: html += '<tr class="lightGray">\n' else: html += '<tr>\n' html += '<td class="gray"><b>%i</b></td>\n' % elements[i] for el in row: if el == 0: html += '<td>%i</td>\n' % el else: html += '<td><b>%i</b></td>\n' % el html += '</tr>\n' i += 1 lgray = not lgray width = int(100 / (len(elements) + 1)) matrix2 = hw2.buildConnMatrix(circuits, elements) html += '''</table><br /> <b>Матрица соединений</b><br /><br /> <table cellspacing="0"> <tr class="gray"> <td width="%i%%" class="white"> </td> ''' % width for el in elements: html += '<td width="%i%%"><b>%i</b></td>\n' % (width, el) html += '</tr>\n' i = 0 lgray = False for row in matrix2: if lgray: html += '<tr class="lightGray">\n' else: html += '<tr>\n' html += '<td class="gray"><b>%i</b></td>\n' % elements[i] k = 0 for val in row: if k == i: html += '<td><b>%i</b></td>\n' % val else: html += '<td>%i</td>\n' % val k += 1 html += '</tr>\n' i += 1 lgray = not lgray html += '''</table><br /><br /> <b>Гамильтонов цикл</b><br/><br/>''' for line in hw5.hamiltonChain(matrix2, elements): html += line + '<br/>' return self.header + html + self.footer
def result(self,data=None): if not data: return self.header+'''Введите <a href="/hw5">данные</a>'''+self.footer circuits=hw2.buildCircuits(data.split('\n')) elements=set() html='''<b>Исходные данные</b><br /><br />''' for i in range(1,len(circuits)+1): if len(circuits[i])<=1: del circuits[i] html+='Цепь №%i пустая <br />' % i continue html+='Цепь №%i %s<br />' % (i,str(circuits[i])) for el in circuits[i]: elements.add(el) elements=list(elements) elements.sort() matrix1=hw2.buildComplexMatrix(circuits,elements) width=int(100/(len(circuits)+1)) html+='''<br /> <b>Матрица комплексов</b><br /><br /> <table cellspacing="0"> <tr class="gray"> <td width="%i%%" class="white"> </td> ''' % width for key in circuits: html+='<td width="%i%%"><b>%i</b></td>\n' % (width,key) html+='</tr>\n' lgray=False i=0 for row in matrix1: if lgray: html+='<tr class="lightGray">\n' else: html+='<tr>\n' html+='<td class="gray"><b>%i</b></td>\n' % elements[i] for el in row: if el==0: html+='<td>%i</td>\n' % el else: html+='<td><b>%i</b></td>\n' % el html+='</tr>\n' i+=1 lgray=not lgray width=int(100/(len(elements)+1)) matrix2=hw2.buildConnMatrix(circuits,elements) html+='''</table><br /> <b>Матрица соединений</b><br /><br /> <table cellspacing="0"> <tr class="gray"> <td width="%i%%" class="white"> </td> ''' % width for el in elements: html+='<td width="%i%%"><b>%i</b></td>\n' % (width,el) html+='</tr>\n' i=0 lgray=False for row in matrix2: if lgray: html+='<tr class="lightGray">\n' else: html+='<tr>\n' html+='<td class="gray"><b>%i</b></td>\n' % elements[i] k=0 for val in row: if k==i: html+='<td><b>%i</b></td>\n' % val else: html+='<td>%i</td>\n' % val k+=1 html+='</tr>\n' i+=1 lgray=not lgray html+='''</table><br /><br /> <b>Гамильтонов цикл</b><br/><br/>''' for line in hw5.hamiltonChain(matrix2,elements): html+=line+'<br/>' return self.header+html+self.footer