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 3.0.12
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 System;
14 using System.Runtime.InteropServices;
15 using System.Collections;
16 
17 public class SatHelper : global::System.IDisposable {
18  private global::System.Runtime.InteropServices.HandleRef swigCPtr;
19  protected bool swigCMemOwn;
20 
21  internal SatHelper(global::System.IntPtr cPtr, bool cMemoryOwn) {
22  swigCMemOwn = cMemoryOwn;
23  swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
24  }
25 
26  internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SatHelper obj) {
27  return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
28  }
29 
30  ~SatHelper() {
31  Dispose();
32  }
33 
34  public virtual void Dispose() {
35  lock(this) {
36  if (swigCPtr.Handle != global::System.IntPtr.Zero) {
37  if (swigCMemOwn) {
38  swigCMemOwn = false;
40  }
41  swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
42  }
43  global::System.GC.SuppressFinalize(this);
44  }
45  }
46 
48  byte[] tmp = new byte[4];
49  System.IntPtr data = operations_research_satPINVOKE.SatHelper_Solve(model_proto.CalculateSize(), ProtoHelper.ProtoToByteArray(model_proto));
50  System.Runtime.InteropServices.Marshal.Copy(data, tmp, 0, 4);
51  int size = System.BitConverter.ToInt32(tmp, 0);
52  byte[] buf = new byte[size + 4];
53  System.Runtime.InteropServices.Marshal.Copy(data, buf, 0, size + 4);
54  // TODO(user): delete the C++ buffer.
55  try {
56  Google.Protobuf.CodedInputStream input =
57  new Google.Protobuf.CodedInputStream(buf, 4, size);
59  proto.MergeFrom(input);
60  return proto;
61  } catch (Google.Protobuf.InvalidProtocolBufferException /*e*/) {
62  throw new System.Exception(
63  "Unable to parse Google.OrTools.Sat.CpSolverResponse protocol message.");
64  }
65 }
66 
67  public static Google.OrTools.Sat.CpSolverResponse SolveWithStringParameters(Google.OrTools.Sat.CpModelProto model_proto, string parameters) {
68  byte[] tmp = new byte[4];
69  System.IntPtr data = operations_research_satPINVOKE.SatHelper_SolveWithStringParameters(model_proto.CalculateSize(), ProtoHelper.ProtoToByteArray(model_proto), parameters);
70  System.Runtime.InteropServices.Marshal.Copy(data, tmp, 0, 4);
71  int size = System.BitConverter.ToInt32(tmp, 0);
72  byte[] buf = new byte[size + 4];
73  System.Runtime.InteropServices.Marshal.Copy(data, buf, 0, size + 4);
74  // TODO(user): delete the C++ buffer.
75  try {
76  Google.Protobuf.CodedInputStream input =
77  new Google.Protobuf.CodedInputStream(buf, 4, size);
79  proto.MergeFrom(input);
80  return proto;
81  } catch (Google.Protobuf.InvalidProtocolBufferException /*e*/) {
82  throw new System.Exception(
83  "Unable to parse Google.OrTools.Sat.CpSolverResponse protocol message.");
84  }
85 }
86 
88  byte[] tmp = new byte[4];
89  System.IntPtr data = operations_research_satPINVOKE.SatHelper_SolveWithStringParametersAndSolutionCallback(model_proto.CalculateSize(), ProtoHelper.ProtoToByteArray(model_proto), parameters, SolutionCallback.getCPtr(callback));
90  System.Runtime.InteropServices.Marshal.Copy(data, tmp, 0, 4);
91  int size = System.BitConverter.ToInt32(tmp, 0);
92  byte[] buf = new byte[size + 4];
93  System.Runtime.InteropServices.Marshal.Copy(data, buf, 0, size + 4);
94  // TODO(user): delete the C++ buffer.
95  try {
96  Google.Protobuf.CodedInputStream input =
97  new Google.Protobuf.CodedInputStream(buf, 4, size);
99  proto.MergeFrom(input);
100  return proto;
101  } catch (Google.Protobuf.InvalidProtocolBufferException /*e*/) {
102  throw new System.Exception(
103  "Unable to parse Google.OrTools.Sat.CpSolverResponse protocol message.");
104  }
105 }
106 
107  public static string ModelStats(Google.OrTools.Sat.CpModelProto model_proto) {
108  string ret = operations_research_satPINVOKE.SatHelper_ModelStats(model_proto.CalculateSize(), ProtoHelper.ProtoToByteArray(model_proto));
109  return ret;
110  }
111 
112  public static string SolverResponseStats(Google.OrTools.Sat.CpSolverResponse response) {
113  string ret = operations_research_satPINVOKE.SatHelper_SolverResponseStats(response.CalculateSize(), ProtoHelper.ProtoToByteArray(response));
114  return ret;
115  }
116 
117  public static string ValidateModel(Google.OrTools.Sat.CpModelProto model_proto) {
118  string ret = operations_research_satPINVOKE.SatHelper_ValidateModel(model_proto.CalculateSize(), ProtoHelper.ProtoToByteArray(model_proto));
119  return ret;
120  }
121 
122  public SatHelper() : this(operations_research_satPINVOKE.new_SatHelper(), true) {
123  }
124 
125 }
126 
127 }
The response returned by a solver trying to solve a CpModelProto.
Definition: CpModel.pb.cs:5495
static byte [] ProtoToByteArray(IMessage message)
Definition: ProtoHelper.cs:21
static string SatHelper_SolverResponseStats(int response_size, byte[] jarg1)
static string SatHelper_ValidateModel(int model_proto_size, byte[] jarg1)
static Google.OrTools.Sat.CpSolverResponse SolveWithStringParametersAndSolutionCallback(Google.OrTools.Sat.CpModelProto model_proto, string parameters, SolutionCallback callback)
Definition: SatHelper.cs:87
static void delete_SatHelper(global::System.Runtime.InteropServices.HandleRef jarg1)
static string SolverResponseStats(Google.OrTools.Sat.CpSolverResponse response)
Definition: SatHelper.cs:112
static Google.OrTools.Sat.CpSolverResponse SolveWithStringParameters(Google.OrTools.Sat.CpModelProto model_proto, string parameters)
Definition: SatHelper.cs:67
void MergeFrom(CpSolverResponse other)
Definition: CpModel.pb.cs:5964
static System.IntPtr SatHelper_SolveWithStringParameters(int model_proto_size, byte[] jarg1, string jarg2)
static Google.OrTools.Sat.CpSolverResponse Solve(Google.OrTools.Sat.CpModelProto model_proto)
Definition: SatHelper.cs:47
static System.IntPtr SatHelper_Solve(int model_proto_size, byte[] jarg1)
A constraint programming problem.
Definition: CpModel.pb.cs:5198
static System.IntPtr SatHelper_SolveWithStringParametersAndSolutionCallback(int model_proto_size, byte[] jarg1, string jarg2, global::System.Runtime.InteropServices.HandleRef jarg3)
static string SatHelper_ModelStats(int model_proto_size, byte[] jarg1)
static string ValidateModel(Google.OrTools.Sat.CpModelProto model_proto)
Definition: SatHelper.cs:117
virtual void Dispose()
Definition: SatHelper.cs:34
static string ModelStats(Google.OrTools.Sat.CpModelProto model_proto)
Definition: SatHelper.cs:107