DotNet Reference

DotNet 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.1
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(false);
32  }
33 
34  public void Dispose() {
35  Dispose(true);
36  global::System.GC.SuppressFinalize(this);
37  }
38 
39  protected virtual void Dispose(bool disposing) {
40  lock(this) {
41  if (swigCPtr.Handle != global::System.IntPtr.Zero) {
42  if (swigCMemOwn) {
43  swigCMemOwn = false;
45  }
46  swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
47  }
48  }
49  }
50 
51  public static Google.OrTools.Sat.CpSolverResponse Solve(Google.OrTools.Sat.CpModelProto model_proto) {
52  byte[] tmp = new byte[4];
53  System.IntPtr data = operations_research_satPINVOKE.SatHelper_Solve(model_proto.CalculateSize(), ProtoHelper.ProtoToByteArray(model_proto));
54  System.Runtime.InteropServices.Marshal.Copy(data, tmp, 0, 4);
55  int size = System.BitConverter.ToInt32(tmp, 0);
56  byte[] buf = new byte[size + 4];
57  System.Runtime.InteropServices.Marshal.Copy(data, buf, 0, size + 4);
58  // TODO(user): delete the C++ buffer.
59  try {
60  Google.Protobuf.CodedInputStream input =
61  new Google.Protobuf.CodedInputStream(buf, 4, size);
62  Google.OrTools.Sat.CpSolverResponse proto = new Google.OrTools.Sat.CpSolverResponse();
63  proto.MergeFrom(input);
64  return proto;
65  } catch (Google.Protobuf.InvalidProtocolBufferException /*e*/) {
66  throw new System.Exception(
67  "Unable to parse Google.OrTools.Sat.CpSolverResponse protocol message.");
68  }
69 }
70 
71  public static Google.OrTools.Sat.CpSolverResponse SolveWithStringParameters(Google.OrTools.Sat.CpModelProto model_proto, string parameters) {
72  byte[] tmp = new byte[4];
73  System.IntPtr data = operations_research_satPINVOKE.SatHelper_SolveWithStringParameters(model_proto.CalculateSize(), ProtoHelper.ProtoToByteArray(model_proto), parameters);
74  System.Runtime.InteropServices.Marshal.Copy(data, tmp, 0, 4);
75  int size = System.BitConverter.ToInt32(tmp, 0);
76  byte[] buf = new byte[size + 4];
77  System.Runtime.InteropServices.Marshal.Copy(data, buf, 0, size + 4);
78  // TODO(user): delete the C++ buffer.
79  try {
80  Google.Protobuf.CodedInputStream input =
81  new Google.Protobuf.CodedInputStream(buf, 4, size);
82  Google.OrTools.Sat.CpSolverResponse proto = new Google.OrTools.Sat.CpSolverResponse();
83  proto.MergeFrom(input);
84  return proto;
85  } catch (Google.Protobuf.InvalidProtocolBufferException /*e*/) {
86  throw new System.Exception(
87  "Unable to parse Google.OrTools.Sat.CpSolverResponse protocol message.");
88  }
89 }
90 
91  public static Google.OrTools.Sat.CpSolverResponse SolveWithStringParametersAndSolutionCallback(Google.OrTools.Sat.CpModelProto model_proto, string parameters, SolutionCallback callback) {
92  byte[] tmp = new byte[4];
93  System.IntPtr data = operations_research_satPINVOKE.SatHelper_SolveWithStringParametersAndSolutionCallback(model_proto.CalculateSize(), ProtoHelper.ProtoToByteArray(model_proto), parameters, SolutionCallback.getCPtr(callback));
94  System.Runtime.InteropServices.Marshal.Copy(data, tmp, 0, 4);
95  int size = System.BitConverter.ToInt32(tmp, 0);
96  byte[] buf = new byte[size + 4];
97  System.Runtime.InteropServices.Marshal.Copy(data, buf, 0, size + 4);
98  // TODO(user): delete the C++ buffer.
99  try {
100  Google.Protobuf.CodedInputStream input =
101  new Google.Protobuf.CodedInputStream(buf, 4, size);
102  Google.OrTools.Sat.CpSolverResponse proto = new Google.OrTools.Sat.CpSolverResponse();
103  proto.MergeFrom(input);
104  return proto;
105  } catch (Google.Protobuf.InvalidProtocolBufferException /*e*/) {
106  throw new System.Exception(
107  "Unable to parse Google.OrTools.Sat.CpSolverResponse protocol message.");
108  }
109 }
110 
111  public static string ModelStats(Google.OrTools.Sat.CpModelProto model_proto) {
112  string ret = operations_research_satPINVOKE.SatHelper_ModelStats(model_proto.CalculateSize(), ProtoHelper.ProtoToByteArray(model_proto));
113  return ret;
114  }
115 
116  public static string SolverResponseStats(Google.OrTools.Sat.CpSolverResponse response) {
117  string ret = operations_research_satPINVOKE.SatHelper_SolverResponseStats(response.CalculateSize(), ProtoHelper.ProtoToByteArray(response));
118  return ret;
119  }
120 
121  public static string ValidateModel(Google.OrTools.Sat.CpModelProto model_proto) {
122  string ret = operations_research_satPINVOKE.SatHelper_ValidateModel(model_proto.CalculateSize(), ProtoHelper.ProtoToByteArray(model_proto));
123  return ret;
124  }
125 
126  public SatHelper() : this(operations_research_satPINVOKE.new_SatHelper(), true) {
127  }
128 
129 }
130 
131 }
static System.IntPtr SatHelper_SolveWithStringParameters(int model_proto_size, byte[] jarg1, string jarg2)
static string SolverResponseStats(Google.OrTools.Sat.CpSolverResponse response)
Definition: SatHelper.cs:116
static byte [] ProtoToByteArray(IMessage message)
Definition: ProtoHelper.cs:21
static Google.OrTools.Sat.CpSolverResponse SolveWithStringParametersAndSolutionCallback(Google.OrTools.Sat.CpModelProto model_proto, string parameters, SolutionCallback callback)
Definition: SatHelper.cs:91
static string SatHelper_SolverResponseStats(int response_size, byte[] jarg1)
virtual void Dispose(bool disposing)
Definition: SatHelper.cs:39
static void delete_SatHelper(global::System.Runtime.InteropServices.HandleRef jarg1)
static string SatHelper_ValidateModel(int model_proto_size, byte[] jarg1)
static string ValidateModel(Google.OrTools.Sat.CpModelProto model_proto)
Definition: SatHelper.cs:121
static string SatHelper_ModelStats(int model_proto_size, byte[] jarg1)
static System.IntPtr SatHelper_SolveWithStringParametersAndSolutionCallback(int model_proto_size, byte[] jarg1, string jarg2, global::System.Runtime.InteropServices.HandleRef jarg3)
static Google.OrTools.Sat.CpSolverResponse SolveWithStringParameters(Google.OrTools.Sat.CpModelProto model_proto, string parameters)
Definition: SatHelper.cs:71
static string ModelStats(Google.OrTools.Sat.CpModelProto model_proto)
Definition: SatHelper.cs:111
static Google.OrTools.Sat.CpSolverResponse Solve(Google.OrTools.Sat.CpModelProto model_proto)
Definition: SatHelper.cs:51
static System.IntPtr SatHelper_Solve(int model_proto_size, byte[] jarg1)