15using System.Collections.Generic;
16using System.Runtime.CompilerServices;
34 private Queue<Term> _terms;
35 private bool _disposed =
false;
54 if (_log_callback is not
null)
56 _solve_wrapper!.AddLogCallbackFromClass(_log_callback);
59 if (_best_bound_callback is not
null)
61 _solve_wrapper!.AddBestBoundCallbackFromClass(_best_bound_callback);
66 _solve_wrapper!.AddSolutionCallback(cb);
74 _solve_wrapper.ClearSolutionCallback(cb);
77 ReleaseSolveWrapper();
83 [MethodImpl(MethodImplOptions.Synchronized)]
84 public void StopSearch() => _solve_wrapper?.StopSearch();
90 _log_callback?.Dispose();
96 _log_callback?.Dispose();
102 _best_bound_callback?.Dispose();
108 _best_bound_callback?.Dispose();
109 _best_bound_callback =
null;
115 var value = index >= 0 ?
Response!.Solution[index] : -
Response!.Solution[-index - 1];
122 long coefficient = 1;
126 _terms =
new Queue<Term>();
138 constant += coefficient * a.
Offset;
139 if (coefficient == 1)
141 foreach (var sub
in a.Terms)
148 foreach (var sub
in a.Terms)
150 _terms.Enqueue(
new Term(sub.expr, sub.coefficient * coefficient));
157 var value = index >= 0 ?
Response!.Solution[index] : -
Response!.Solution[-index - 1];
158 constant += coefficient * value;
161 throw new ArgumentException(
"Cannot evaluate a literal in an integer expression.");
163 throw new ArgumentException(
"Cannot evaluate '" + expr +
"' in an integer expression");
166 if (!_terms.TryDequeue(out var term))
172 coefficient = term.coefficient;
185 return Response!.Solution[index] != 0;
189 return Response!.Solution[-index - 1] == 0;
194 throw new ArgumentException(
"Cannot evaluate '" + literal.ToString() +
"' as a boolean literal");
215 _best_bound_callback?.Dispose();
216 _log_callback?.Dispose();
217 ReleaseSolveWrapper();
221 [MethodImpl(MethodImplOptions.Synchronized)]
222 private void CreateSolveWrapper()
228 [MethodImpl(MethodImplOptions.Synchronized)]
229 private void ReleaseSolveWrapper()
232 _solve_wrapper =
null;
242 public override void NewMessage(
string message) => _delegate_(message);