Reverted mistaken missed functionality

This commit is contained in:
hamilcarBarca17
2023-03-15 13:40:20 -06:00
parent db437cf179
commit fd2da99277
3 changed files with 43 additions and 1 deletions
+14
View File
@@ -61,6 +61,20 @@ cp_sat_wrapper_cp_model_stats(unsigned char* model_buf, size_t model_size) {
return strdup(stats.c_str()); 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* extern "C" char*
cp_sat_wrapper_validate_cp_model(unsigned char* model_buf, size_t model_size) { cp_sat_wrapper_validate_cp_model(unsigned char* model_buf, size_t model_size) {
sat::CpModelProto model; sat::CpModelProto model;
+28
View File
@@ -17,6 +17,11 @@ extern "C" {
out_size: &mut usize, out_size: &mut usize,
) -> *mut u8; ) -> *mut u8;
fn cp_sat_wrapper_cp_model_stats(model_buf: *const u8, model_size: usize) -> *mut c_char; 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_validate_cp_model(model_buf: *const u8, model_size: usize) -> *mut c_char;
fn cp_sat_wrapper_solution_is_feasible( fn cp_sat_wrapper_solution_is_feasible(
model_buf: *const u8, model_buf: *const u8,
@@ -81,6 +86,29 @@ pub fn cp_model_stats(model: &proto::CpModelProto) -> String {
res 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 /// Verifies that the given model satisfies all the properties
/// described in the proto comments. Returns an empty string if it is /// described in the proto comments. Returns an empty string if it is
/// the case, otherwise fails at the first error and returns a /// the case, otherwise fails at the first error and returns a
+1 -1
View File
@@ -33,7 +33,7 @@
//! let response = model.solve(); //! let response = model.solve();
//! println!( //! println!(
//! "{}", //! "{}",
//! cp_sat::ffi::cp_model_stats(&model.proto()) //! cp_sat::ffi::cp_solver_response_stats(&response, false)
//! ); //! );
//! //!
//! if response.status() == CpSolverStatus::Optimal { //! if response.status() == CpSolverStatus::Optimal {