我是量角器的新手,我希望更改下拉菜单中的值。但是我的下拉菜单是使用primeNG的p-dropdown实现的。更改下拉值的当前实现是在普通选择-选项菜单中完成的。
这是我的
代码Walls = [(1,2),(1,5),(8,5),(8,3),(11,3),(11,1),(5,1),(5,3),(4,3),(4,1),(1,1),(1,2)]
Lights = [(2,4),(2,2),(5,4)] # In red can only be turned on by one switch
Switches = [(4,4),(6,3),(6,2)] # In green can only turn on one light
graph = {}
residual = {}
def ccw(A,B,C):
return (C[1]-A[1]) * (B[0]-A[0]) > (B[1]-A[1]) * (C[0]-A[0])
# Return true if line segments AB and CD intersect
# Source: http://bryceboe.com/2006/10/23/line-segment-intersection-algorithm/
def intersect(A,B,C,D):
return ccw(A,C,D) != ccw(B,C,D) and ccw(A,B,C) != ccw(A,B,D)
def visible(pt1,pt2,Walls):
x1,y1 = pt1
x2,y2 = pt2
for i,wall in enumerate(Walls[:-1]):
x3,y3 = wall
x4,y4 = Walls[i+1]
if intersect((x1,y1),(x2,y2),(x3,y3),(x4,y4)):
return False
return True
def edges(L,M):
# Empty dictionary that will store the edges
graph['End'] = []
for i in range(0, len(L)): # for all the switches stores them as the key
graph[M[i]] = []
for switch in range(0, len(M)): # for all the switches check to see what lights are visible
for light in range(0, len(M)):
if visible(M[switch],L[light],Walls) == True:
graph[M[switch]].append(L[light]) # If the lights are visible store them in a list as the value
graph['start'] = []
for switch in range(0, len(M)): # Connects the start (sink) to the switches
graph['start'].append(M[switch])
for light in range(0, len(L)): # Connects each light to the End (sink)
graph[L[light]] = ['End']
return graph
def bfs_shortest_path(graphs, s, t): # from https://pythoninwonderland.wordpress.com/2017/03/18/how-to-implement-breadth-first-search-in-python/ Valerio Velardo
# keep track of explored nodes
global graph
visited = []
# keep track of all the paths to be checked
queue = [[s]]
# return path if start is goal
if s == t:
return "That was easy! Start = goal"
# keeps looping until all possible paths have been checked
while queue:
# pop the first path from the queue
path = queue.pop(0)
# get the last node from the path
node = path[-1]
if node not in visited:
newnode = graph[node]
# go through all neighbour nodes, construct a new path and
# push it into the queue
for othernodes in newnode:
newedgest = list(path)
newedgest.append(othernodes)
queue.append(newedgest)
# return path if neighbour is goal
if othernodes == t:
return newedgest, True
# mark node as explored
visited.append(node)
# in case there's no path between the 2 nodes
return "So sorry, but a connecting path doesn't exist :(", False
def maxflow(graphs):
# Path taken
graph = edges(Lights, Switches)
path, tf = bfs_shortest_path(graph,'start','End')
while tf == True:
# for all the nodes in the graph delete them so they cannot be travelled to
for i in graph['start']:
if i in path:
graph['start'].remove(i) # Removes first node in graph aka Switch
print(graph,'switch removed')
for newnode in graph[path[1]]:
if newnode in path:
graph[path[1]].remove(newnode) # Removes next node aka Light
print(graph, 'light removed')
for othernode in graph[path[2]]:
if othernode in path:
graph[path[2]].remove(othernode)
print(graph, 'end removed')
residual = graph
return residual, 'residual graph'
print(maxflow(graph))
print(graph)
newgraph = {'End': [], (4, 4): [(2, 2), (5, 4)], (6, 3): [(2, 4), (5, 4)], (6, 2): [(5, 4)], 'start': [(6, 3), (6, 2)], (2, 4): [], (2, 2): ['End'], (5, 4): ['End']}
print(bfs_shortest_path(newgraph, 'start', 'End'))
现在,我希望使用量角器更改值。怎么做?