Question: Can you fill the following python code such that it passes the three tests I give you? Python code: from pulp import * def encode
Can you fill the following python code such that it passes the three tests I give you?
Python code:
from pulp import
def encodeandsolvethreecoloringn edgelist:
assert n 'Graph must have at least one vertex'
assert all i and i n and j and j n and i j for ij in edgelist 'Edge list is not well formed'
prob LpProblemThree Color', LpMinimize
# Formulate the decision variables
# Add the constraints for each vertex and edge in the graph.
# Solve and interpret the status of the solution.
# Return the result in the required form to pass the tests below.
# your code here
raise NotImplementedError
Test :
n
edgelist
flag colorassign encodeandsolvethreecoloringn edgelist
assert flag True, 'Error: Graph is three colorable but your code wrongly returns flag False'
printfThree color assignment: colorassign
def checkthreecolorassignn edgelist, colorassign:
assert lencolorassign n f'Error: The list of color assignments has lencolorassign entries but must be same as number of vertices n
assert all col r or col b or col g for col in colorassign f'Error: Each entry in color assignment list must be r g or b Your code returned: colorassign
for i j in edgelist:
ci colorassigni
cj colorassignj
assert ci cj f Error: For edge ij we have same color assignment ci cj
printSuccess: Three coloring assignment checks out!!
checkthreecolorassignn edgelist, colorassign
printPassed: points!
Test :
n
edgelist
flag colorassign encodeandsolvethreecoloringn edgelist
assert flag False, 'Error: Graph is NOT three colorable but your code wrongly returns flag True'
printPassed: points!
Test :
n
edgelist
flag colorassign encodeandsolvethreecoloringn edgelist
assert flag True, 'Error: Graph is three colorable but your code wrongly returns flag False'
printfThree color assignment: colorassign
def checkthreecolorassignn edgelist, colorassign:
assert lencolorassign n f'Error: The list of color assignments has lencolorassign entries but must be same as number of vertices n
assert all col r or col b or col g for col in colorassign f'Error: Each entry in color assignment list must be r g or b Your code returned: colorassign
for i j in edgelist:
ci colorassigni
cj colorassignj
assert ci cj f Error: For edge ij we have same color assignment ci cj
printSuccess: Three coloring assignment checks out!!
checkthreecolorassignn edgelist, colorassign
printPassed: points!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
