我有下一个代码错误
codealcance.tex
58
Package inputenc Error: Invalid UTF-8 byte sequence.
See the inputenc package documentation for explanation.
Type H <return> for immediate help.
...
l.58 while stack: #en cada iteración
这些是 57-59 行
57print("\nantes\n")
58while stack: #en cada iteración va agregando elementos que faltan por visitar a la pila
59vertex = stack.pop()
这是 codealcance.tex
\begin{lstlisting}[caption={Segundo alcance DFS y orden topologico},label={lst:alcance2},style=customc]
import time
from collections import deque
class abstract_graph:
def __init__(self,_edges):
self.edges=_edges
self.nodes={u for u,v in self.edges} | {v for u,v in self.edges}
def adjacency_list(self):
pass
class simple_digraph(abstract_graph):
def __init__(self,_edges):
self.edges=_edges
print("las aristas: ", self.edges)
self.nodes={u for u,v in self.edges if u!=None} | {v for u,v in self.edges if v!=None}
a={u for u,v in self.edges if u!=None} #en una ariista (u,v) en a se guarda listsa con cada u
b={v for u,v in self.edges if v!=None}
c= a | b #en c se guarda la union de los nodos
def adjacency_list(self):
adjacent=lambda n : {v for u,v in self.edges if u==n and v!=None}
return {v:adjacent(v) for v in self.nodes} #se crea un diccionario en el que la key es un nodo y los elementos del diccionario son nodos adyacentes
def in_degree(self):
degree= lambda n : len({u for u,v in self.edges if v==n and u!=None})
return {v:degree(v) for v in self.nodes}
def topo_sort(graph):
topology = []
degree = graph.in_degree()
adj=graph.adjacency_list()
stack=[key for (key,value) in G.in_degree().items() if value==0]
while stack:
vertex = stack.pop()
topology.append(vertex)
for m in adj[vertex]:
degree[m] -= 1
if not degree[m]:
stack.append(m)
if len(topology) < len(graph.nodes):
raise ValueError('graph contains cycle')
return topology
def dfs(graph, start):
visited, stack, path = set(), [start],[]
print("\nantes\n")
while stack: #en cada iteración va agregando elementos que faltan por visitar a la pila
vertex = stack.pop()
print("\nel vertice:", vertex)
if vertex not in visited:
visited.add(vertex)
path.append(vertex)
stack.extend(graph[vertex] - visited)
print("EL DFS es:",path)
return path
E=[('LINK1', 'LINK2'),('LINK1', 'LINK4'),('LINK2', 'LINK3'),('LINK2', 'LINK5'),('LINK3', 'LINK4'),('LINK3', 'LINK5'),('LINK4', 'LINK5'),('LINK6', 'LINK7')]
G=simple_digraph(E)
print("LISTA ADYACENCIA", G.adjacency_list())
print("IN DEGREE",G.in_degree())
start=time.clock()
ddfs=dfs(G.adjacency_list(),'LINK1') #ejecuta la busqueda en proundidad
L=topo_sort(G) #ejecuta el ordenamiento topologico
print('\nOrden topologico',L)
\end{lstlisting}
在我的主程序中我添加了 utf8 包
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage[spanish,es-tabla]{babel} % espanol
\decimalpoint
\usepackage[utf8]{inputenc}
\usepackage{graphicx} % graficos
\usepackage{amsmath}
\usepackage{listings}