Skip to content

Instantly share code, notes, and snippets.

@raydiak
Created May 16, 2021 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raydiak/4b41408ebf17ee8e103886ba54f23c4f to your computer and use it in GitHub Desktop.
Save raydiak/4b41408ebf17ee8e103886ba54f23c4f to your computer and use it in GitHub Desktop.
#!/usr/bin/env raku
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, CArray[num64], CArray[int32], 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 ( $count, @row, @colno, $constr_type, $rh) {
add_constraintex(self, $count, CArray[num64].new(@row».Num), CArray[int32].new(@colno), $constr_type, $rh.Num );
}
method getLPName () {
get_lp_name(self)
}
}
my $lp = LPrec.new(0,2);
say $lp.getLPName();
$lp.addConstraintex(1,[1],[1],1,1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment