add CpModel::ExportToFile for CP-SAT in all non C++ languages

This commit is contained in:
Laurent Perron
2020-10-08 14:32:57 +02:00
parent 8259943b1d
commit d123dfadf6
5 changed files with 17 additions and 6 deletions

View File

@@ -1003,6 +1003,11 @@ public final class CpModel {
return SatHelper.validateModel(model());
}
/** Write the model as a ascii protocol buffer to 'file'.*/
public Boolean ExportToFile(String file) {
return SatHelper.writeModelToFile(file);
}
// Helpers
long[] toLongArray(int[] values) {

View File

@@ -323,10 +323,10 @@ namespace Google.OrTools.Sat
res.Demands.Add(Convert.ToInt64(d));
}
ct.Proto.Reservoir = res;
res.MinLevel = min_level;
res.MaxLevel = max_level;
ct.Proto.Reservoir = res;
return ct;
}
@@ -350,10 +350,11 @@ namespace Google.OrTools.Sat
{
res.Actives.Add(var.Index);
}
res.MinLevel = min_level;
res.MaxLevel = max_level;
ct.Proto.Reservoir = res;
return ct;
}
@@ -690,7 +691,7 @@ namespace Google.OrTools.Sat
}
foreach (KeyValuePair<IntVar, long> it in dict)
{
objective.Vars.Add(it.Key.Index);
objective.Vars.Add(it.Key.Index);
objective.Coeffs.Add(minimize ? it.Value : -it.Value);
}
}
@@ -702,7 +703,7 @@ namespace Google.OrTools.Sat
return SatHelper.ModelStats(model_);
}
public Boolean WriteModelToFile(String filename) {
public Boolean ExportToFile(String filename) {
return SatHelper.WriteModelToFile(model_, filename);
}

View File

@@ -62,6 +62,7 @@ PROTO2_RETURN(operations_research::sat::CpSolverResponse,
%rename (solverResponseStats) operations_research::sat::SatHelper::SolverResponseStats;
%rename (validateModel) operations_research::sat::SatHelper::ValidateModel;
%rename (variableDomain) operations_research::sat::SatHelper::VariableDomain;
%rename (writeModelToFile) operations_research::sat::SatHelper::WriteModelToFile;
%typemap(javaimports) operations_research::sat::SatHelper %{
import com.google.ortools.util.Domain;

View File

@@ -1505,6 +1505,10 @@ class CpModel(object):
"""Returns a string indicating that the model is invalid."""
return pywrapsat.SatHelper.ValidateModel(self.__model)
def ExportToFile(self, file):
"""Write the model as a ascii protocol buffer to 'file'."""
return pywrapsat.SatHelper.WriteModelToFile(file)
def AssertIsBooleanVariable(self, x):
if isinstance(x, IntVar):
var = self.__model.variables[x.Index()]

View File

@@ -61,6 +61,7 @@ PY_PROTO_TYPEMAP(ortools.sat.sat_parameters_pb2,
%unignore operations_research::sat::SatHelper::SolverResponseStats;
%unignore operations_research::sat::SatHelper::ValidateModel;
%unignore operations_research::sat::SatHelper::VariableDomain;
%unignore operations_research::sat::SatHelper::WriteModelToFile;
%feature("director") operations_research::sat::SolutionCallback;
%unignore operations_research::sat::SolutionCallback;
@@ -98,4 +99,3 @@ PY_PROTO_TYPEMAP(ortools.sat.sat_parameters_pb2,
%include "ortools/sat/swig_helper.h"
%unignoreall