Closed JoelPasvolsky closed 6 years ago
The following map coloring does not work
import dwavebinarycsp from dwave.system.samplers import DWaveSampler from dwave.system.composites import EmbeddingComposite import operator
provinces = ['AB', 'BC', 'NT', 'SK', 'YT'] neighbors = [('AB', 'BC'), ('AB', 'NT'), ('AB', 'SK'), ('BC', 'NT'), ('BC', 'YT'), ('NT', 'SK'), ('NT', 'YT')]
one_color_configurations = {(0, 0, 0, 1), (0, 0, 1, 0), (0, 1, 0, 0), (1, 0, 0, 0)}
csp = dwavebinarycsp.ConstraintSatisfactionProblem(dwavebinarycsp.BINARY)
for province in provinces: vars = [province+'0', province+'1', province+'2', province+'3'] csp.add_constraint(one_color_configurations, vars)
for neighbor in neighbors: v, u = neighbor for i in range(4): var = [v+str(i), u+str(i)] csp.add_constraint(operator.ne, var)
bqm = dwavebinarycsp.stitch(csp)
sampler = EmbeddingComposite(DWaveSampler()) response = sampler.sample(bqm, chain_strength=3, num_reads=1000)
An issue of problem construction.
for neighbor in neighbors: for i in range(4): var = [v+str(i), u+str(i)] csp.add_constraint([(0, 0), (0, 1), (1, 0)], var)
The following map coloring does not work
HALF CANADA 4 COLORS
import dwavebinarycsp from dwave.system.samplers import DWaveSampler from dwave.system.composites import EmbeddingComposite import operator
provinces = ['AB', 'BC', 'NT', 'SK', 'YT'] neighbors = [('AB', 'BC'), ('AB', 'NT'), ('AB', 'SK'), ('BC', 'NT'), ('BC', 'YT'), ('NT', 'SK'), ('NT', 'YT')]
one_color_configurations = {(0, 0, 0, 1), (0, 0, 1, 0), (0, 1, 0, 0), (1, 0, 0, 0)}
csp = dwavebinarycsp.ConstraintSatisfactionProblem(dwavebinarycsp.BINARY)
for province in provinces: vars = [province+'0', province+'1', province+'2', province+'3'] csp.add_constraint(one_color_configurations, vars)
for neighbor in neighbors: v, u = neighbor for i in range(4): var = [v+str(i), u+str(i)] csp.add_constraint(operator.ne, var)
bqm = dwavebinarycsp.stitch(csp)
sampler = EmbeddingComposite(DWaveSampler()) response = sampler.sample(bqm, chain_strength=3, num_reads=1000)