Reverted mistaken missed functionality
This commit is contained in:
@@ -61,6 +61,20 @@ cp_sat_wrapper_cp_model_stats(unsigned char* model_buf, size_t model_size) {
|
||||
return strdup(stats.c_str());
|
||||
}
|
||||
|
||||
extern "C" char*
|
||||
cp_sat_wrapper_cp_solver_response_stats(
|
||||
unsigned char* response_buf,
|
||||
size_t response_size,
|
||||
bool has_objective)
|
||||
{
|
||||
sat::CpSolverResponse response;
|
||||
const bool res = response.ParseFromArray(response_buf, response_size);
|
||||
assert(res);
|
||||
|
||||
const std::string stats = sat::CpSolverResponseStats(response, has_objective);
|
||||
return strdup(stats.c_str());
|
||||
}
|
||||
|
||||
extern "C" char*
|
||||
cp_sat_wrapper_validate_cp_model(unsigned char* model_buf, size_t model_size) {
|
||||
sat::CpModelProto model;
|
||||
|
||||
+28
@@ -17,6 +17,11 @@ extern "C" {
|
||||
out_size: &mut usize,
|
||||
) -> *mut u8;
|
||||
fn cp_sat_wrapper_cp_model_stats(model_buf: *const u8, model_size: usize) -> *mut c_char;
|
||||
fn cp_sat_wrapper_cp_solver_response_stats(
|
||||
response_buf: *const u8,
|
||||
response_size: usize,
|
||||
has_objective: bool,
|
||||
) -> *mut c_char;
|
||||
fn cp_sat_wrapper_validate_cp_model(model_buf: *const u8, model_size: usize) -> *mut c_char;
|
||||
fn cp_sat_wrapper_solution_is_feasible(
|
||||
model_buf: *const u8,
|
||||
@@ -81,6 +86,29 @@ pub fn cp_model_stats(model: &proto::CpModelProto) -> String {
|
||||
res
|
||||
}
|
||||
|
||||
/// Returns a string with some statistics on the solver response.
|
||||
///
|
||||
/// If the second argument is false, we will just display NA for the
|
||||
/// objective value instead of zero. It is not really needed but it
|
||||
/// makes things a bit clearer to see that there is no objective.
|
||||
pub fn cp_solver_response_stats(response: &proto::CpSolverResponse, has_objective: bool) -> String {
|
||||
let mut response_buf = Vec::default();
|
||||
response.encode(&mut response_buf).unwrap();
|
||||
let char_ptr = unsafe {
|
||||
cp_sat_wrapper_cp_solver_response_stats(
|
||||
response_buf.as_ptr(),
|
||||
response_buf.len(),
|
||||
has_objective,
|
||||
)
|
||||
};
|
||||
let res = unsafe { CStr::from_ptr(char_ptr) }
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_owned();
|
||||
unsafe { libc::free(char_ptr as _) };
|
||||
res
|
||||
}
|
||||
|
||||
/// Verifies that the given model satisfies all the properties
|
||||
/// described in the proto comments. Returns an empty string if it is
|
||||
/// the case, otherwise fails at the first error and returns a
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@
|
||||
//! let response = model.solve();
|
||||
//! println!(
|
||||
//! "{}",
|
||||
//! cp_sat::ffi::cp_model_stats(&model.proto())
|
||||
//! cp_sat::ffi::cp_solver_response_stats(&response, false)
|
||||
//! );
|
||||
//!
|
||||
//! if response.status() == CpSolverStatus::Optimal {
|
||||
|
||||
Reference in New Issue
Block a user