Skip to content

Commit

Permalink
Merge pull request #4 from conjure-cp/main
Browse files Browse the repository at this point in the history
Merge changes from main
  • Loading branch information
gskorokhod authored Nov 7, 2023
2 parents dff4cdf + 87422ed commit 8dc53d5
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 20 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/code-coverage-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
});
console.log(callee_run);
// from manual inspection in jq, seems to hold head.sha for PR, not
// whatever GITHUB_SHA is.
return callee_run.head_sha;
Expand All @@ -51,7 +54,7 @@ jobs:
commit-message: "Actions: Code Coverage for ${{ steps.sha.outputs.result }}"

- name: If on main branch, copy coverage report to /main.
if: github.ref == 'refs/heads/main'
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: ./deploy
Expand Down Expand Up @@ -116,7 +119,7 @@ jobs:
- name: "Generate indexes"
run: |
./etc/ci/genindex.py pages/coverage/${{ steps.sha.outputs.result }}
./etc/ci/genindex.py pages/coverage/latest
./etc/ci/genindex.py pages/coverage/main
./etc/ci/genindex.py pages/coverage/
- uses: JamesIves/github-pages-deploy-action@v4
Expand Down
20 changes: 16 additions & 4 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ jobs:
echo -e "submodule_sha=$(./etc/ci/get_submodules_hash.sh)" >> "$GITHUB_OUTPUT"
echo -e "submodule_sha=$(./etc/ci/get_submodules_hash.sh)"
- name: Get Sha
id: sha
run: |
if [[ ${{ github.event_name }} == 'pull_request' ]]
then
echo -e "sha=${{ github.event.pull_request.head.sha }}" >> "$GITHUB_OUTPUT"
echo -e "sha=${{ github.event.pull_request.head.sha }}"
else
echo -e "sha=${{ github.sha }}" >> "$GITHUB_OUTPUT"
echo -e "sha=${{ github.sha }}"
fi
- name: Set up cache
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -61,14 +73,14 @@ jobs:
- name: Archive code coverage results
uses: actions/upload-artifact@v3
with:
name: code-coverage-${{ github.sha }}
name: code-coverage-${{ steps.sha.outputs.sha }}
path: deploy/**

- name: Format summary
run : |
CONJURE_OXIDE_URL="https://conjure-cp.github.io/conjure-oxide/coverage/${{ github.sha }}/conjure-oxide"
MINION_URL="https://conjure-cp.github.io/conjure-oxide/coverage/${{ github.sha }}/minion"
CHUFFED_URL="https://conjure-cp.github.io/conjure-oxide/coverage/${{ github.sha }}/chuffed"
CONJURE_OXIDE_URL="https://conjure-cp.github.io/conjure-oxide/coverage/${{ steps.sha.outputs.sha }}/conjure-oxide"
MINION_URL="https://conjure-cp.github.io/conjure-oxide/coverage/${{ steps.sha.outputs.sha }}/minion"
CHUFFED_URL="https://conjure-cp.github.io/conjure-oxide/coverage/${{ steps.sha.outputs.sha }}/chuffed"
CONJURE_OXIDE_LATEST="https://conjure-cp.github.io/conjure-oxide/coverage/main/conjure-oxide"
MINION_LATEST="https://conjure-cp.github.io/conjure-oxide/coverage/main/minion"
Expand Down
1 change: 1 addition & 0 deletions solvers/chuffed/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fn bind() {
.allowlist_function("destroy_vec_intvar")
.allowlist_function("p_addVars")
.allowlist_function("p_setcallback")
.allowlist_function("p_print")
.allowlist_function("branch_IntVar")
.clang_arg("-Ivendor/build") // generated from configure.py
.clang_arg("-Ivendor")
Expand Down
17 changes: 15 additions & 2 deletions solvers/chuffed/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pub mod bindings {

pub mod wrappers {
use crate::bindings::{
all_different, branch_IntVar, createVar, createVars, make_vec_intvar, vec, ConLevel,
IntVar, ValBranch, VarBranch,
all_different, branch_IntVar, createVar, createVars, make_vec_intvar, output_vars1,
var_sym_break, vec, ConLevel, IntVar, ValBranch, VarBranch,
};
use core::ptr;

Expand Down Expand Up @@ -50,4 +50,17 @@ pub mod wrappers {
branch_IntVar(x, var_branch, val_branch);
}
}

pub unsafe fn output_vars_wrapper(x: *mut vec<*mut IntVar>) {
unsafe {
// output_vars1 takes in an vec<IntVar*> instead of branching
output_vars1(x);
}
}

pub unsafe fn var_sym_break_wrapper(x: *mut vec<*mut IntVar>) {
unsafe {
var_sym_break(x);
}
}
}
19 changes: 16 additions & 3 deletions solvers/chuffed/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use chuffed_rs::bindings::{
get_idx, new_dummy_problem, p_addVars, p_setcallback, vec, ConLevel_CL_DEF, IntVar,
get_idx, new_dummy_problem, p_addVars, p_print, p_setcallback, vec, ConLevel_CL_DEF, IntVar,
VarBranch_VAR_INORDER, VarBranch_VAR_MIN_MIN,
};
use chuffed_rs::wrappers::{all_different_wrapper, branch_wrapper, create_vars};
use chuffed_rs::wrappers::{
all_different_wrapper, branch_wrapper, create_vars, output_vars_wrapper, var_sym_break_wrapper,
};

unsafe fn post_constraints(_n: i32) -> *mut vec<*mut IntVar> {
// Create constant
Expand All @@ -16,15 +18,23 @@ unsafe fn post_constraints(_n: i32) -> *mut vec<*mut IntVar> {
// Post some branchings
branch_wrapper(x as _, VarBranch_VAR_INORDER, VarBranch_VAR_MIN_MIN);

// Declare output variables (optional)
output_vars_wrapper(x);

// Declare symmetries (optional)
var_sym_break_wrapper(x);

// Return the variable
x
}

// Custom printing function for this problem
#[no_mangle]
pub unsafe extern "C" fn callback(x: *mut vec<*mut IntVar>) {
print!("First output is: {:?}", get_idx(x, 0));
print!("First output is: {}", get_idx(x, 0));
}

// Entry point for running this problem
fn main() {
let args: Vec<String> = std::env::args().collect();

Expand All @@ -43,5 +53,8 @@ fn main() {
p_addVars(p, x);
// Call problem.setcallback()
p_setcallback(p, Some(callback));
// Commented out currently as trying to print causes the assertion of
// isFixed() in IntVar::getVal() to fail.
// p_print(p);
}
}
67 changes: 67 additions & 0 deletions solvers/chuffed/tests/chuffed_basic_run.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use chuffed_rs::bindings::{
get_idx, new_dummy_problem, p_addVars, p_print, p_setcallback, vec, ConLevel_CL_DEF, IntVar,
VarBranch_VAR_INORDER, VarBranch_VAR_MIN_MIN,
};
use chuffed_rs::wrappers::{
all_different_wrapper, branch_wrapper, create_vars, output_vars_wrapper, var_sym_break_wrapper,
};

/// Creates the variable for the test problem and posts some constraints and
/// branchings on it.
unsafe fn post_constraints(_n: i32) -> *mut vec<*mut IntVar> {
// Create constant
let n: i32 = _n;
// Create some variables
let x: *mut vec<*mut IntVar> = create_vars(n, 0, n, false);

// Post some constraints
all_different_wrapper(x, ConLevel_CL_DEF);

// Post some branchings
branch_wrapper(x as _, VarBranch_VAR_INORDER, VarBranch_VAR_MIN_MIN);

// Declare output variables (optional)
output_vars_wrapper(x);

// Declare symmetries (optional)
var_sym_break_wrapper(x);

// Return the variable
x
}

/// Custom printing function for this test problem
#[no_mangle]
pub unsafe extern "C" fn callback(x: *mut vec<*mut IntVar>) {
print!("First output is: {}", get_idx(x, 0));
}

/// Basic test to make sure that running the ffi bindings and wrappers does not
/// crash
#[test]
fn run_basic_problem() {
let args: Vec<String> = std::env::args().collect();

if args.len() != 2 {
println!("Invalid number of arguments");
return;
}

let n: i32 = args[1].parse().expect("Invalid input");

unsafe {
let x = post_constraints(n);
// make new dummy problem
let p = new_dummy_problem();
// Call problem.addvars()
p_addVars(p, x);
// Call problem.setcallback()
p_setcallback(p, Some(callback));
// Commented out currently as trying to print causes the assertion of
// isFixed() in IntVar::getVal() to fail.
// p_print(p);

// Pass test if no crash occurs
assert!(true);
}
}
14 changes: 8 additions & 6 deletions solvers/chuffed/wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ void p_addVars(DummyProblem *p, vec<IntVar *> *_searchVars) {
void p_setcallback(DummyProblem *p, void (*_callback)(vec<IntVar *> *)) {
p->setcallback(_callback);
}
IntVar* get_idx(vec<IntVar *> *x, int i) { return *x[i]; }
void p_print(DummyProblem *p) { p->print(); }

vec<IntVar*>* make_vec_intvar() {
return new vec<IntVar*>();
int get_idx(vec<IntVar *> *x, int i) {
IntVar *var = *x[i];
int t = var->getVal();
return t;
}

void destroy_vec_intvar(vec<IntVar*>* v) {
delete v;
}
vec<IntVar *> *make_vec_intvar() { return new vec<IntVar *>(); }

void destroy_vec_intvar(vec<IntVar *> *v) { delete v; }

void branch_IntVar(vec<IntVar *> *x, VarBranch var_branch,
ValBranch val_branch) {
Expand Down
7 changes: 4 additions & 3 deletions solvers/chuffed/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ class DummyProblem {
DummyProblem *new_dummy_problem();
void p_addVars(DummyProblem *p, vec<IntVar *> *_searchVars);
void p_setcallback(DummyProblem *p, void (*_callback)(vec<IntVar *> *));
IntVar* get_idx(vec<IntVar *> *x, int i);
void p_print(DummyProblem *p);
int get_idx(vec<IntVar *> *x, int i);

vec<IntVar*>* make_vec_intvar();
void destroy_vec_intvar(vec<IntVar*>* v);
vec<IntVar *> *make_vec_intvar();
void destroy_vec_intvar(vec<IntVar *> *v);

void branch_IntVar(vec<IntVar *> *x, VarBranch var_branch,
ValBranch val_branch);

0 comments on commit 8dc53d5

Please sign in to comment.