use NativeCall;
# /usr/lib64/liblpsolve55.so
# lp_solve types in lp_types.h
# REAL double -> raku: num64
class LPrec is repr('CPointer'){
# has int32 $.alignmentspacer is rw;
# has Str $.lp_name is rw;
# has int32 $.rows;
# has int32 $.columns;
# ... lot's of other items to add (see lp_lib.h)
# lprec *make_lp(int rows, int columns);
sub make_lp(int32,int32) returns LPrec is native('lpsolve55') {*}
# unsigned char set_add_rowmode(lprec *lp, unsigned char turnon);
sub set_add_rowmode( LPrec, bool) is native('lpsolve55') {*}
# unsigned char add_constraintex(lprec *lp, int count, REAL *row, int *colno, int constr_type, REAL rh);
sub add_constraintex( LPrec, int32, num64 is rw, int32 is rw, int32, num64) is native('lpsolve55') {*}
# unsigned char set_lp_name(lprec *lp, char *lpname);
sub set_lp_name( LPrec, Str) returns bool is native('lpsolve55') {*}
# char *get_lp_name(lprec *lp);
sub get_lp_name( LPrec ) returns Str is native('lpsolve55') {*}
method new (int32 $rows, int32 $columns) {
my $lp = make_lp( $rows, $columns );
set_add_rowmode( $lp, True);
set_lp_name( $lp, "LP model");
return $lp;
}
method addConstraintex ( Int $count, Int $row, Int $colno, Int $constr_type, Int $rh) {
my int32 $v_count = $count;
# say $v_count.WHICH;
my num64 $v_row = $row.Num;
my $pv_row = nativecast(Pointer[num64],$v_row);
my int32 $v_colno = $colno;
my int32 $v_constr_type = $constr_type;
my num64 $v_rh = $rh.Num;
# say $rhp.WHICH;
say "Done";
add_constraintex (self, $v_count, $pv_row, $v_colno, $v_constr_type, $v_rh );
# add_constraintex (self, $v_count, Pointer[num64].new($v_row), Pointer[int32].new($v_colno), $v_constr_type, $v_rh );
}
method getLPName () {
get_lp_name(self)
}
}
my $lp = LPrec.new(0,2);
say $lp.getLPName();
$lp.addConstraintex(1,1,1,1,1);