DotNet Reference

.Net Reference

SatHelper.cs
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // <auto-generated />
3 //
4 // This file was automatically generated by SWIG (http://www.swig.org).
5 // Version 4.0.2
6 //
7 // Do not make changes to this file unless you know what you are doing--modify
8 // the SWIG interface file instead.
9 //------------------------------------------------------------------------------
10 
11 namespace Google.OrTools.Sat {
12 
13 using Google.OrTools.Util;
14 
15 public class SatHelper : global::System.IDisposable {
16  private global::System.Runtime.InteropServices.HandleRef swigCPtr;
17  protected bool swigCMemOwn;
18 
19  internal SatHelper(global::System.IntPtr cPtr, bool cMemoryOwn) {
20  swigCMemOwn = cMemoryOwn;
21  swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
22  }
23 
24  internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SatHelper obj) {
25  return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
26  }
27 
28  ~SatHelper() {
29  Dispose(false);
30  }
31 
32  public void Dispose() {
33  Dispose(true);
34  global::System.GC.SuppressFinalize(this);
35  }
36 
37  protected virtual void Dispose(bool disposing) {
38  lock(this) {
39  if (swigCPtr.Handle != global::System.IntPtr.Zero) {
40  if (swigCMemOwn) {
41  swigCMemOwn = false;
43  }
44  swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
45  }
46  }
47  }
48 
50  byte[] tmp = new byte[4];
51  System.IntPtr data = operations_research_satPINVOKE.SatHelper_Solve(model_proto.CalculateSize(), ProtoHelper.ProtoToByteArray(model_proto));
52  System.Runtime.InteropServices.Marshal.Copy(data, tmp, 0, 4);
53  int size = System.BitConverter.ToInt32(tmp, 0);
54  byte[] buf = new byte[size + 4];
55  System.Runtime.InteropServices.Marshal.Copy(data, buf, 0, size + 4);
56  // TODO(user): delete the C++ buffer.
57  try {
58  Google.Protobuf.CodedInputStream input =
59  new Google.Protobuf.CodedInputStream(buf, 4, size);
61  proto.MergeFrom(input);
62  return proto;
63  } catch (Google.Protobuf.InvalidProtocolBufferException /*e*/) {
64  throw new System.Exception(
65  "Unable to parse Google.OrTools.Sat.CpSolverResponse protocol message.");
66  }
67 }
68 
69  public static Google.OrTools.Sat.CpSolverResponse SolveWithStringParameters(Google.OrTools.Sat.CpModelProto model_proto, string parameters) {
70  byte[] tmp = new byte[4];
71  System.IntPtr data = operations_research_satPINVOKE.SatHelper_SolveWithStringParameters(model_proto.CalculateSize(), ProtoHelper.ProtoToByteArray(model_proto), parameters);
72  System.Runtime.InteropServices.Marshal.Copy(data, tmp, 0, 4);
73  int size = System.BitConverter.ToInt32(tmp, 0);
74  byte[] buf = new byte[size + 4];
75  System.Runtime.InteropServices.Marshal.Copy(data, buf, 0, size + 4);
76  // TODO(user): delete the C++ buffer.
77  try {
78  Google.Protobuf.CodedInputStream input =
79  new Google.Protobuf.CodedInputStream(buf, 4, size);
81  proto.MergeFrom(input);
82  return proto;
83  } catch (Google.Protobuf.InvalidProtocolBufferException /*e*/) {
84  throw new System.Exception(
85  "Unable to parse Google.OrTools.Sat.CpSolverResponse protocol message.");
86  }
87 }
88 
90  byte[] tmp = new byte[4];
91  System.IntPtr data = operations_research_satPINVOKE.SatHelper_SolveWithStringParametersAndSolutionCallback(model_proto.CalculateSize(), ProtoHelper.ProtoToByteArray(model_proto), parameters, SolutionCallback.getCPtr(callback));
92  System.Runtime.InteropServices.Marshal.Copy(data, tmp, 0, 4);
93  int size = System.BitConverter.ToInt32(tmp, 0);
94  byte[] buf = new byte[size + 4];
95  System.Runtime.InteropServices.Marshal.Copy(data, buf, 0, size + 4);
96  // TODO(user): delete the C++ buffer.
97  try {
98  Google.Protobuf.CodedInputStream input =
99  new Google.Protobuf.CodedInputStream(buf, 4, size);
101  proto.MergeFrom(input);
102  return proto;
103  } catch (Google.Protobuf.InvalidProtocolBufferException /*e*/) {
104  throw new System.Exception(
105  "Unable to parse Google.OrTools.Sat.CpSolverResponse protocol message.");
106  }
107 }
108 
109  public static string ModelStats(Google.OrTools.Sat.CpModelProto model_proto) {
110  string ret = operations_research_satPINVOKE.SatHelper_ModelStats(model_proto.CalculateSize(), ProtoHelper.ProtoToByteArray(model_proto));
111  return ret;
112  }
113 
114  public static string SolverResponseStats(Google.OrTools.Sat.CpSolverResponse response) {
115  string ret = operations_research_satPINVOKE.SatHelper_SolverResponseStats(response.CalculateSize(), ProtoHelper.ProtoToByteArray(response));
116  return ret;
117  }
118 
119  public static string ValidateModel(Google.OrTools.Sat.CpModelProto model_proto) {
120  string ret = operations_research_satPINVOKE.SatHelper_ValidateModel(model_proto.CalculateSize(), ProtoHelper.ProtoToByteArray(model_proto));
121  return ret;
122  }
123 
124  public static Domain VariableDomain(Google.OrTools.Sat.IntegerVariableProto variable_proto) {
125  Domain ret = new Domain(operations_research_satPINVOKE.SatHelper_VariableDomain(variable_proto.CalculateSize(), ProtoHelper.ProtoToByteArray(variable_proto)), true);
126  return ret;
127  }
128 
129  public static bool WriteModelToFile(Google.OrTools.Sat.CpModelProto model_proto, string filename) {
130  bool ret = operations_research_satPINVOKE.SatHelper_WriteModelToFile(model_proto.CalculateSize(), ProtoHelper.ProtoToByteArray(model_proto), filename);
132  return ret;
133  }
134 
135  public SatHelper() : this(operations_research_satPINVOKE.new_SatHelper(), true) {
136  }
137 
138 }
139 
140 }
static global::System.Exception Retrieve()
SatHelper()
Definition: SatHelper.cs:135
The response returned by a solver trying to solve a CpModelProto.
Definition: CpModel.pb.cs:7464
Definition: Domain.cs:17
static bool Pending
static Google.OrTools.Sat.CpSolverResponse SolveWithStringParametersAndSolutionCallback(Google.OrTools.Sat.CpModelProto model_proto, string parameters, SolutionCallback callback)
Definition: SatHelper.cs:89
An integer variable.
Definition: CpModel.pb.cs:244
static void delete_SatHelper(global::System.Runtime.InteropServices.HandleRef jarg1)
static byte[] ProtoToByteArray(IMessage message)
Definition: ProtoHelper.cs:22
static System.IntPtr SatHelper_SolveWithStringParameters(int model_proto_size, byte[] jarg1, string jarg2)
Definition: SatHelper.cs:15
static System.IntPtr SatHelper_Solve(int model_proto_size, byte[] jarg1)
static string ValidateModel(Google.OrTools.Sat.CpModelProto model_proto)
Definition: SatHelper.cs:119
static System.IntPtr SatHelper_SolveWithStringParametersAndSolutionCallback(int model_proto_size, byte[] jarg1, string jarg2, global::System.Runtime.InteropServices.HandleRef jarg3)
using System
Definition: Program.cs:14
static Google.OrTools.Sat.CpSolverResponse SolveWithStringParameters(Google.OrTools.Sat.CpModelProto model_proto, string parameters)
Definition: SatHelper.cs:69
A constraint programming problem.
Definition: CpModel.pb.cs:7044
bool swigCMemOwn
Definition: SatHelper.cs:17
static global::System.IntPtr SatHelper_VariableDomain(int variable_proto_size, byte[] jarg1)
static Google.OrTools.Sat.CpSolverResponse Solve(Google.OrTools.Sat.CpModelProto model_proto)
Definition: SatHelper.cs:49
static string SatHelper_ValidateModel(int model_proto_size, byte[] jarg1)
virtual void Dispose(bool disposing)
Definition: SatHelper.cs:37
void MergeFrom(CpSolverResponse other)
Definition: CpModel.pb.cs:8110
static string ModelStats(Google.OrTools.Sat.CpModelProto model_proto)
Definition: SatHelper.cs:109
static string SatHelper_ModelStats(int model_proto_size, byte[] jarg1)
static Domain VariableDomain(Google.OrTools.Sat.IntegerVariableProto variable_proto)
Definition: SatHelper.cs:124
Definition: Domain.cs:11
Definition: ProtoHelper.cs:21
void Dispose()
Definition: SatHelper.cs:32
static string SatHelper_SolverResponseStats(int response_size, byte[] jarg1)
static bool WriteModelToFile(Google.OrTools.Sat.CpModelProto model_proto, string filename)
Definition: SatHelper.cs:129
static string SolverResponseStats(Google.OrTools.Sat.CpSolverResponse response)
Definition: SatHelper.cs:114
static bool SatHelper_WriteModelToFile(int model_proto_size, byte[] jarg1, string jarg2)
Definition: CpModel.pb.cs:12