naev 0.12.6
nlua_linopt.c File Reference

Handles Linear linoptization in Lua. More...

#include "nlua_linopt.h"
#include "log.h"
#include "nluadef.h"
Include dependency graph for nlua_linopt.c:

Go to the source code of this file.

Data Structures

struct  LuaLinOpt_t
 Our cute little linear program wrapper. More...

Macros

#define LINOPT_MAX_TM    1000
#define METH_DEF   GLP_PRIMAL
#define PRICING_DEF   GLP_PT_PSE
#define R_TEST_DEF   GLP_RT_HAR
#define PRESOLVE_DEF   GLP_OFF
#define BR_TECH_DEF   GLP_BR_DTH
#define BT_TECH_DEF   GLP_BT_BLB
#define PP_TECH_DEF   GLP_PP_ALL
#define SR_HEUR_DEF   GLP_ON
#define FP_HEUR_DEF   GLP_OFF
#define PS_HEUR_DEF   GLP_OFF
#define GMI_CUTS_DEF   GLP_OFF
#define MIR_CUTS_DEF   GLP_OFF
#define COV_CUTS_DEF   GLP_OFF
#define CLQ_CUTS_DEF   GLP_OFF
#define STRCHK(val, ret)
#define GETOPT_IOCP(name, func, def)
#define GETOPT_SMCP(name, func, def)

Functions

static int linoptL_gc (lua_State *L)
 Frees a linopt.
static int linoptL_eq (lua_State *L)
 Compares two linopts to see if they are the same.
static int linoptL_new (lua_State *L)
 Opens a new linopt.
static int linoptL_size (lua_State *L)
 Adds columns to the linear program.
static int linoptL_addcols (lua_State *L)
 Adds columns to the linear program.
static int linoptL_addrows (lua_State *L)
 Adds rows to the linear program.
static int linoptL_setcol (lua_State *L)
 Adds an optimization column.
static int linoptL_setrow (lua_State *L)
 Adds an optimization row.
static int linoptL_loadmatrix (lua_State *L)
 Loads the entire matrix for the linear program.
static int linoptL_solve (lua_State *L)
 Solves the linear optimization problem.
static int linoptL_readProblem (lua_State *L)
 Reads an optimization problem from a file for debugging purposes.
static int linoptL_writeProblem (lua_State *L)
 Writes an optimization problem to a file for debugging purposes.
int nlua_loadLinOpt (nlua_env env)
 Loads the linopt library.
LuaLinOpt_tlua_tolinopt (lua_State *L, int ind)
 Lua bindings to interact with linopts.
LuaLinOpt_tluaL_checklinopt (lua_State *L, int ind)
 Gets linopt at index or raises error if there is no linopt at index.
LuaLinOpt_tlua_pushlinopt (lua_State *L, LuaLinOpt_t linopt)
 Pushes a linopt on the stack.
int lua_islinopt (lua_State *L, int ind)
 Checks to see if ind is a linopt.
static const char * linopt_status (int retval)
static const char * linopt_error (int retval)
static int opt_meth (const char *str, int def)
static int opt_pricing (const char *str, int def)
static int opt_r_test (const char *str, int def)
static int opt_br_tech (const char *str, int def)
static int opt_bt_tech (const char *str, int def)
static int opt_pp_tech (const char *str, int def)
static int opt_onoff (const char *str, int def)

Variables

static const luaL_Reg linoptL_methods []

Detailed Description

Handles Linear linoptization in Lua.

Definition in file nlua_linopt.c.

Macro Definition Documentation

◆ BR_TECH_DEF

#define BR_TECH_DEF   GLP_BR_DTH

Definition at line 522 of file nlua_linopt.c.

◆ BT_TECH_DEF

#define BT_TECH_DEF   GLP_BT_BLB

Definition at line 523 of file nlua_linopt.c.

◆ CLQ_CUTS_DEF

#define CLQ_CUTS_DEF   GLP_OFF

Definition at line 531 of file nlua_linopt.c.

◆ COV_CUTS_DEF

#define COV_CUTS_DEF   GLP_OFF

Definition at line 530 of file nlua_linopt.c.

◆ FP_HEUR_DEF

#define FP_HEUR_DEF   GLP_OFF

Definition at line 526 of file nlua_linopt.c.

◆ GETOPT_IOCP

#define GETOPT_IOCP ( name,
func,
def )
Value:
do { \
lua_getfield( L, 2, #name ); \
parm_iocp.name = func( luaL_optstring( L, -1, NULL ), def ); \
lua_pop( L, 1 ); \
} while ( 0 )

Definition at line 620 of file nlua_linopt.c.

◆ GETOPT_SMCP

#define GETOPT_SMCP ( name,
func,
def )
Value:
do { \
lua_getfield( L, 2, #name ); \
parm_smcp.name = func( luaL_optstring( L, -1, NULL ), def ); \
lua_pop( L, 1 ); \
} while ( 0 )

Definition at line 626 of file nlua_linopt.c.

◆ GMI_CUTS_DEF

#define GMI_CUTS_DEF   GLP_OFF

Definition at line 528 of file nlua_linopt.c.

◆ LINOPT_MAX_TM

#define LINOPT_MAX_TM    1000

Maximum time to optimize (in ms). Applied to linear relaxation \ and MIP independently.

Definition at line 25 of file nlua_linopt.c.

◆ METH_DEF

#define METH_DEF   GLP_PRIMAL

Definition at line 517 of file nlua_linopt.c.

◆ MIR_CUTS_DEF

#define MIR_CUTS_DEF   GLP_OFF

Definition at line 529 of file nlua_linopt.c.

◆ PP_TECH_DEF

#define PP_TECH_DEF   GLP_PP_ALL

Definition at line 524 of file nlua_linopt.c.

◆ PRESOLVE_DEF

#define PRESOLVE_DEF   GLP_OFF

Definition at line 520 of file nlua_linopt.c.

◆ PRICING_DEF

#define PRICING_DEF   GLP_PT_PSE

Definition at line 518 of file nlua_linopt.c.

◆ PS_HEUR_DEF

#define PS_HEUR_DEF   GLP_OFF

Definition at line 527 of file nlua_linopt.c.

◆ R_TEST_DEF

#define R_TEST_DEF   GLP_RT_HAR

Definition at line 519 of file nlua_linopt.c.

◆ SR_HEUR_DEF

#define SR_HEUR_DEF   GLP_ON

Definition at line 525 of file nlua_linopt.c.

◆ STRCHK

#define STRCHK ( val,
ret )
Value:
if ( strcmp( str, ( val ) ) == 0 ) \
return ( ret );

Definition at line 545 of file nlua_linopt.c.

Function Documentation

◆ linopt_error()

const char * linopt_error ( int retval)
static

Definition at line 445 of file nlua_linopt.c.

◆ linopt_status()

const char * linopt_status ( int retval)
static

Definition at line 426 of file nlua_linopt.c.

◆ linoptL_addcols()

int linoptL_addcols ( lua_State * L)
static

Adds columns to the linear program.

Lua function parameter: LinOpt lp Linear program to modify. Lua function parameter: number cols Number of columns to add.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: add_cols

Definition at line 244 of file nlua_linopt.c.

◆ linoptL_addrows()

int linoptL_addrows ( lua_State * L)
static

Adds rows to the linear program.

Lua function parameter: LinOpt lp Linear program to modify. Lua function parameter: number rows Number of rows to add.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: add_rows

Definition at line 260 of file nlua_linopt.c.

◆ linoptL_eq()

int linoptL_eq ( lua_State * L)
static

Compares two linopts to see if they are the same.

Lua function parameter: Optim d1 Optim 1 to compare. Lua function parameter: Optim d2 Optim 2 to compare. Lua return parameter: boolean true if both linopts are the same.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __eq

Definition at line 171 of file nlua_linopt.c.

◆ linoptL_gc()

int linoptL_gc ( lua_State * L)
static

Frees a linopt.

Lua function parameter: Optim linopt Optim to free.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __gc

Definition at line 156 of file nlua_linopt.c.

◆ linoptL_loadmatrix()

int linoptL_loadmatrix ( lua_State * L)
static

Loads the entire matrix for the linear program.

Lua function parameter: LinOpt lp Linear program to modify. Lua function parameter: number row_indices Indices of the rows. Lua function parameter: number col_indices Indices of the columns. Lua function parameter: number coefficients Values of the coefficients.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: load_matrix

Definition at line 379 of file nlua_linopt.c.

◆ linoptL_new()

int linoptL_new ( lua_State * L)
static

Opens a new linopt.

Lua function parameter:[opt=nil] string name Name of the optimization program. Lua function parameter: number cols Number of columns in the optimization program. Lua function parameter: number rows Number of rows in the optimization program. Lua function parameter:[opt=false] boolean maximize Whether to maximize (rather than minimize) the function. Lua return parameter: Optim New linopt object.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: new

Definition at line 191 of file nlua_linopt.c.

◆ linoptL_readProblem()

int linoptL_readProblem ( lua_State * L)
static

Reads an optimization problem from a file for debugging purposes.

Lua function parameter: string fname Path to the file. Lua function parameter:[opt=false] boolean glpk_format Whether the program is in GLPK format instead of MPS format. Lua function parameter:[opt=false] boolean maximize Whether to maximize (rather than minimize) the function. Lua return parameter: LinOpt Linear program in the file.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: read_problem

Definition at line 781 of file nlua_linopt.c.

◆ linoptL_setcol()

int linoptL_setcol ( lua_State * L)
static

Adds an optimization column.

Lua function parameter: LinOpt lp Linear program to modify. Lua function parameter: number index Index of the column to set. Lua function parameter: string name Name of the column being added. Lua function parameter: number coefficient Coefficient of the objective function being added. Lua function parameter:[opt="real"] string kind Kind of the column being added. Can be either "real", "integer", or "binary". Lua function parameter:[opt=nil] number lb Lower bound of the column. Lua function parameter:[opt=nil] number ub Upper bound of the column.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: set_col

Definition at line 283 of file nlua_linopt.c.

◆ linoptL_setrow()

int linoptL_setrow ( lua_State * L)
static

Adds an optimization row.

Lua function parameter: LinOpt lp Linear program to modify. Lua function parameter: number index Index of the row to set. Lua function parameter: string name Name of the row being added. Lua function parameter:[opt=nil] number lb Lower bound of the row. Lua function parameter:[opt=nil] number ub Upper bound of the row.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: set_row

Definition at line 338 of file nlua_linopt.c.

◆ linoptL_size()

int linoptL_size ( lua_State * L)
static

Adds columns to the linear program.

Lua function parameter: LinOpt lp Linear program to modify. Lua return parameter: number Number of columns in the linear program. Lua return parameter: number Number of rows in the linear program.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: size

Definition at line 229 of file nlua_linopt.c.

◆ linoptL_solve()

int linoptL_solve ( lua_State * L)
static

Solves the linear optimization problem.

Lua function parameter: LinOpt lp Linear program to modify. Lua return parameter: number The value of the primal funcation. Lua return parameter: table Table of column values.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: solve

Definition at line 640 of file nlua_linopt.c.

◆ linoptL_writeProblem()

int linoptL_writeProblem ( lua_State * L)
static

Writes an optimization problem to a file for debugging purposes.

Lua function parameter: LinOpt lp Linear program to write. Lua function parameter: string fname Path to write the program to. Lua function parameter:[opt=false] boolean glpk_format Whether to write the program in GLPK format instead of MPS format.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: write_problem

Definition at line 818 of file nlua_linopt.c.

◆ lua_islinopt()

int lua_islinopt ( lua_State * L,
int ind )

Checks to see if ind is a linopt.

Parameters
LLua state to check.
indIndex position to check.
Returns
1 if ind is a linopt.

Definition at line 134 of file nlua_linopt.c.

◆ lua_pushlinopt()

LuaLinOpt_t * lua_pushlinopt ( lua_State * L,
LuaLinOpt_t linopt )

Pushes a linopt on the stack.

Parameters
LLua state to push linopt into.
linoptOptim to push.
Returns
Newly pushed linopt.

Definition at line 118 of file nlua_linopt.c.

◆ lua_tolinopt()

LuaLinOpt_t * lua_tolinopt ( lua_State * L,
int ind )

Lua bindings to interact with linopts.

Lua module: linopt

Gets linopt at index.

Parameters
LLua state to get linopt from.
indIndex position to find the linopt.
Returns
Optim found at the index in the state.

Definition at line 91 of file nlua_linopt.c.

◆ luaL_checklinopt()

LuaLinOpt_t * luaL_checklinopt ( lua_State * L,
int ind )

Gets linopt at index or raises error if there is no linopt at index.

Parameters
LLua state to get linopt from.
indIndex position to find linopt.
Returns
Optim found at the index in the state.

Definition at line 103 of file nlua_linopt.c.

◆ nlua_loadLinOpt()

int nlua_loadLinOpt ( nlua_env env)

Loads the linopt library.

Parameters
envEnvironment to load linopt library into.
Returns
0 on success.

Definition at line 73 of file nlua_linopt.c.

◆ opt_br_tech()

int opt_br_tech ( const char * str,
int def )
static

Definition at line 576 of file nlua_linopt.c.

◆ opt_bt_tech()

int opt_bt_tech ( const char * str,
int def )
static

Definition at line 588 of file nlua_linopt.c.

◆ opt_meth()

int opt_meth ( const char * str,
int def )
static

Definition at line 548 of file nlua_linopt.c.

◆ opt_onoff()

int opt_onoff ( const char * str,
int def )
static

Definition at line 609 of file nlua_linopt.c.

◆ opt_pp_tech()

int opt_pp_tech ( const char * str,
int def )
static

Definition at line 599 of file nlua_linopt.c.

◆ opt_pricing()

int opt_pricing ( const char * str,
int def )
static

Definition at line 558 of file nlua_linopt.c.

◆ opt_r_test()

int opt_r_test ( const char * str,
int def )
static

Definition at line 567 of file nlua_linopt.c.

Variable Documentation

◆ linoptL_methods

const luaL_Reg linoptL_methods[]
static
Initial value:
= {
{ "__gc", linoptL_gc },
{ "__eq", linoptL_eq },
{ "new", linoptL_new },
{ "size", linoptL_size },
{ "add_cols", linoptL_addcols },
{ "add_rows", linoptL_addrows },
{ "set_col", linoptL_setcol },
{ "set_row", linoptL_setrow },
{ "load_matrix", linoptL_loadmatrix },
{ "solve", linoptL_solve },
{ "read_problem", linoptL_readProblem },
{ "write_problem", linoptL_writeProblem },
{ 0, 0 } }
static int linoptL_loadmatrix(lua_State *L)
Loads the entire matrix for the linear program.
static int linoptL_setcol(lua_State *L)
Adds an optimization column.
static int linoptL_solve(lua_State *L)
Solves the linear optimization problem.
static int linoptL_gc(lua_State *L)
Frees a linopt.
static int linoptL_readProblem(lua_State *L)
Reads an optimization problem from a file for debugging purposes.
static int linoptL_size(lua_State *L)
Adds columns to the linear program.
static int linoptL_addrows(lua_State *L)
Adds rows to the linear program.
static int linoptL_new(lua_State *L)
Opens a new linopt.
static int linoptL_addcols(lua_State *L)
Adds columns to the linear program.
static int linoptL_setrow(lua_State *L)
Adds an optimization row.
static int linoptL_eq(lua_State *L)
Compares two linopts to see if they are the same.
static int linoptL_writeProblem(lua_State *L)
Writes an optimization problem to a file for debugging purposes.

Optim metatable methods.

Definition at line 52 of file nlua_linopt.c.