Respuesta :
Answer:
Algorithm given below
Explanation:
Algorithm:
proc create-node( event )
out-adj-list[event] <- empty-list
in-degree[event] <- 0
endproc
proc create-edge( start, end )
push( out-adj-list[ start ], end )
in-degree[ end ] <- in-degree[ end ] + 1
endproc
for p \in { P_i }
create-node( birth[p] )
create-node( death[p] )
create-edge( birth[p], death[p] )
endfor
for (p, q) \in DiedBefore
create-edge( death[p], birth[q] )
endfor
for (p, q) \in Coexisted
create-edge( birth[p], death[q] )
create-edge( birth[q], death[p] )
endfor
eligible-node-list <- empty-list
for p \in { P_i }
if in-degree[ birth[p] ] = 0
push(eligible-node-list, birth[p])
endif
endfor
event-date-separation = 200yrs / (2*|{P_i}|)
order <- 0
while eligible-node-list is non-empty
event = pop(eligible-node-list)
order <- order + 1
dates[ event ] = START_DATE + order * event-date-separation
for following-event \in out-adj-list[event]
in-degree[ following-event ] <- in-degree[ following-event ] - 1
if in-degree[ following-event ] = 0
push( eligible-node-list, following-event )
endif
endfor
endwhile
if order < 2*|{P_i}|
return INCONSISTENT_DATA
else
return CONSISTENT_DATA, dates
endif
In this exercise we have to use the knowledge of computational language in python to write the code.
We have the codes in the attached image.
The code in python can be found as:
proc create-node( event )
out-adj-list[event]
in-degree[event]
endproc
proc create-edge( start, end )
push( out-adj-list[ start ], end )
in-degree[ end ] <- in-degree[ end ] + 1
endproc
for p \in { P_i }
create-node( birth[p] )
create-node( death[p] )
create-edge( birth[p], death[p] )
endfor
for (p, q) \in DiedBefore
create-edge( death[p], birth[q] )
end
for
for (p, q) \in Coexisted
create-edge( birth[p], death[q] )
create-edge( birth[q], death[p] )
end
for
eligible-node-list
for p \in { P_i }
if in-degree[ birth[p] ] = 0
push(eligible-node-list, birth[p])
end
if
end
for
event-date-separation = 200yrs / (2*|{P_i}|)
order <- 0
while eligible-node-list is non-empty
event = pop(eligible-node-list)
order
dates[ event ] = START_DATE + order * event-date-separation
for following-event \in out-adj-list[event]
in-degree[ following-event ]
in-degree[ following-event ] - 1
if in-degree[ following-event ] = 0
push( eligible-node-list, following-event )
endif
endfor
endwhile
if order < 2*|{P_i}|
return INCONSISTENT_DATA
else
return CONSISTENT_DATA, dates
See more about python at brainly.com/question/26104476
