Hi!
I just started to get familiar with eht CP-SAT API, and was thinking to solve smaller problems to learn the basics.
I'm tryign to solve the "magic series" / "magic sequence" problem based on the following pseudo-code:
int n = 5
range D = 0..n-1
var{int} series[D] in D;
solve {
forall(k in D)
series[k] = sum(i in D) (series[i]=k)I spent the last 2 days to implement the reified constraints, and I think I went through all the availabe materials that are available on the internet. Also found an example which solves it with the old solver: https://github.com/google/or-tools/blob/master/examples/python/magic_sequence_distribute.py . I didn't find any material on the distribute function and whether it is available in the new solver or not.
Anyway my goal is to find out how can I sum literal sonditions. I tried several versions with different type of constarints. I got at least to a version which doesn't throw error, but it says the problem is infeasable.
from ortools.sat.python import cp_model
model = cp_model.CpModel()n = 5values = range(n)
my_vars = [model.NewIntVar(0,n-1, 'x%i' % i) for i in values]
for k in values: tmp_array = [] for i in values: tmp_var = model.NewBoolVar("") model.Add((my_vars[i] == k)).OnlyEnforceIf(tmp_var) tmp_array.append(tmp_var) model.Add(sum(tmp_array) == k) #model.Add(my_vars[k] == sum((my_vars[i] == k) for i in values))#model.AddSumConstraint([my_vars[i] == k for i in values], k, k)
solver = cp_model.CpSolver()solution_printer = SolutionPrinter(my_vars)status = solver.SearchForAllSolutions(model, solution_printer)
Can someone help how to implement reified constarints?
Thank you!
--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.