--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/5831a9f1-222b-453e-bcbb-e9e94fe501bd%40googlegroups.com.
Hello, I was having basically the same problem and use the method Xiang Chen describes in his answer.
{ protected CSolverModel myModel;
public CSolverIntVar(CSolverModel myModel_, IntVar intvar_) { this.myModel = myModel_; this.intvar = intvar_; }
public IntVar intvar { get; private set; }
/// <summary> /// Creates a new IntVar whose value is equivalent to the result of a == b /// and returns it encapsulated as a MyIntVar /// </summary> /// <param name="a">The MyIntVar whose equality is being checked</param> /// <param name="b">The long against which to check the value.</param> /// <returns>A new MyIntVar whose value is equivalent to the expression a == b</returns> public static CSolverIntVar operator == (CSolverIntVar a, long b) { // Check for null operand if (object.ReferenceEquals(a, null)) { throw new ArgumentException("Attempt to equate a null MyIntVar with a long."); } string resultName = string.Format("{0}=={1}", a.intvar.Name(), b); IntVar iv = a.myModel.NewBoolVar(resultName); a.myModel.Add(a.intvar == b).OnlyEnforceIf(iv); a.myModel.Add(a.intvar != b).OnlyEnforceIf(iv.Not()); return new CSolverIntVar(a.myModel,iv); }
/// <summary> /// Creates a new IntVar whose value is equivalent to the result of a != b /// and returns it encapsulated as a MyIntVar /// </summary> /// <param name="a">The MyIntVar whose inequality is being checked</param> /// <param name="b">The long against which to check the value.</param> /// <returns>A new MyIntVar whose value is equivalent to the expression a != b</returns> public static CSolverIntVar operator !=(CSolverIntVar a, long b) { // Check for null operand if (object.ReferenceEquals(a, null)) { throw new ArgumentException("Attempt to compare a null MyIntVar with a long."); } string resultName = string.Format("{0}!={1}", a.intvar.Name(), b); IntVar iv = a.myModel.NewBoolVar(resultName); a.myModel.Add(a.intvar != b).OnlyEnforceIf(iv); a.myModel.Add(a.intvar == b).OnlyEnforceIf(iv.Not()); return new CSolverIntVar(a.myModel, iv); }--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/f5571025-0de4-43c5-a096-1366b012680b%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/f5571025-0de4-43c5-a096-1366b012680b%40googlegroups.com.
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/48ba1422-34ea-4334-bf5d-6a1a3b914a63%40googlegroups.com.