-
Notifications
You must be signed in to change notification settings - Fork 2
/
P7.py
56 lines (46 loc) · 1.88 KB
/
P7.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from typing import List
from Graph import Graph
from Production import Production
from Vertex import Vertex
from Edge import Edge
class P7(Production):
@staticmethod
def apply(vertices: List[Vertex], graph: Graph):
if vertices[0].label == 'F':
new_vertex = graph.create_add_vertex('F', vertices[0].attributes)
edges_to_del = []
edges_to_add = []
for edge in graph.edges.values():
edge_to_del_flag = False
if edge.label == 'd' and \
edge.vertex_to_index == vertices[0].index:
edge_to_add = Edge(graph.next_edge_index(), edge.label,
edge.vertex_from_index, new_vertex.index,
edge.attributes)
edges_to_add.append(edge_to_add)
edge_to_del_flag = True
if edge.label == 'd' and \
edge.vertex_from_index == vertices[0].index:
edge_to_add = Edge(graph.next_edge_index(), edge.label,
new_vertex.index, edge.vertex_to_index,
edge.attributes)
edges_to_add.append(edge_to_add)
edge_to_del_flag = True
if edge_to_del_flag:
edges_to_del.append(edge)
for edge in edges_to_del:
graph.remove_edge(edge)
for edge in edges_to_add:
graph.add_edge(edge)
@staticmethod
def description() -> str:
return ('name: P7\n'
'L: (F)\n'
"P: (F) (F')\n"
"""c: {((d, in, 0): (F', Z, d, in)),
((d, out, 0): (F', P, d, out)),
CopyRest}\n"""
"where ' is used for temporary indexing only\n")
@staticmethod
def to_string():
return "P7"