本文整理汇总了Java中org.gnu.glpk.GLPK类的典型用法代码示例。如果您正苦于以下问题:Java GLPK类的具体用法?Java GLPK怎么用?Java GLPK使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GLPK类属于org.gnu.glpk包,在下文中一共展示了GLPK类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import org.gnu.glpk.GLPK; //导入依赖的package包/类
public static void initialize() {
try {
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
// try to load Windows library
System.loadLibrary("glpk_4_47_java");
} else {
// try to load Linux library
System.loadLibrary("glpk_java");
}
} catch (UnsatisfiedLinkError e) {
System.err
.println("The dynamic link library for GLPK for Java could not be "
+ "loaded.\nConsider using\njava -Djava.library.path=");
throw e;
}
GLPK.glp_java_set_msg_lvl(GLPKConstants.GLP_JAVA_MSG_LVL_OFF);
GLPK.glp_term_out(GLPKConstants.GLP_OFF);
}
示例2: removeRows
import org.gnu.glpk.GLPK; //导入依赖的package包/类
@Override
public void removeRows(int[] indexes) throws CPException {
SWIGTYPE_p_int ind = GLPK.new_intArray( indexes.length + 1 );
for (int i = 0; i < indexes.length; i++) {
GLPK.intArray_setitem( ind, i + 1, indexes[i] );
}
GLPK.glp_del_rows( m_model, indexes.length, ind );
GLPK.delete_intArray( ind );
m_simplexCtrl.setPresolve( GLPKConstants.GLP_ON );
m_colStats = null;
m_rowStats = null;
}
示例3: setRowBounds
import org.gnu.glpk.GLPK; //导入依赖的package包/类
public void setRowBounds(int rowIndex, double lBound, double uBound) {
if (lBound == Double.NEGATIVE_INFINITY) {
if (uBound == Double.POSITIVE_INFINITY) {
//Set the row free
GLPK.glp_set_row_bnds( m_model, rowIndex, GLPKConstants.GLP_FR, 0, 0 );
} else {
//Upper bound
GLPK.glp_set_row_bnds( m_model, rowIndex, GLPKConstants.GLP_UP, 0, uBound );
}
} else {
if (uBound == Double.POSITIVE_INFINITY) {
//Lower bound
GLPK.glp_set_row_bnds( m_model, rowIndex, GLPKConstants.GLP_LO, lBound, 0 );
} else {
//Double bound
GLPK.glp_set_row_bnds( m_model, rowIndex, GLPKConstants.GLP_DB, lBound, uBound );
}
}
}
示例4: setRowCoefficients
import org.gnu.glpk.GLPK; //导入依赖的package包/类
protected static void setRowCoefficients(glp_prob model, int index, double[] row, double rhs, LPSolver.ROW_TYPE type) {
SWIGTYPE_p_double newRow = GLPK.new_doubleArray( row.length + 1 );
SWIGTYPE_p_int ind = GLPK.new_intArray( row.length + 1 );
//Set the coefficients
for (int i = 0; i < row.length; i++) {
GLPK.doubleArray_setitem( newRow, i + 1, row[i] );
GLPK.intArray_setitem( ind, i + 1, i + 1 );
}
GLPK.glp_set_mat_row( model, index, row.length, ind, newRow );
GLPK.glp_set_row_bnds( model, index, GLPKUtils.genericRowTypeToGLPKType( type ), rhs, rhs );
GLPK.delete_doubleArray( newRow );
GLPK.delete_intArray( ind );
}
示例5: getRowCoefficients
import org.gnu.glpk.GLPK; //导入依赖的package包/类
protected static double[] getRowCoefficients(glp_prob model, int index) {
int colNum = GLPK.glp_get_num_cols( model );
SWIGTYPE_p_double coeffs = GLPK.new_doubleArray( colNum + 1 );
SWIGTYPE_p_int indices = GLPK.new_intArray( colNum + 1 );
int len = GLPK.glp_get_mat_row( model, index, indices, coeffs );
double[] allCoeffs = new double[GLPK.glp_get_num_cols( model )];
for (int i = 0; i < len; i++) {
int varIndex = GLPK.intArray_getitem( indices, i + 1 );
allCoeffs[varIndex - 1] = GLPK.doubleArray_getitem( coeffs, i + 1 );
}
GLPK.delete_intArray( indices );
GLPK.delete_doubleArray( coeffs );
return allCoeffs;
}
示例6: setColumnCoefficients
import org.gnu.glpk.GLPK; //导入依赖的package包/类
protected static void setColumnCoefficients(glp_prob model, int index, double[] column) {
SWIGTYPE_p_double col = GLPK.new_doubleArray( column.length );
SWIGTYPE_p_int ind = GLPK.new_intArray( column.length );
//Set the coefficients
for (int i = 1; i < column.length; i++) {
GLPK.doubleArray_setitem( col, i, column[i] );
GLPK.intArray_setitem( ind, i, i );
}
GLPK.glp_set_mat_col( model, index, column.length - 1, ind, col );
GLPK.glp_set_col_kind( model, index, GLPKConstants.GLP_CV );
GLPK.glp_set_col_bnds( model, index, GLPKConstants.GLP_LO, 0, Double.MAX_VALUE );
GLPK.delete_doubleArray( col );
GLPK.delete_intArray( ind );
}
示例7: getConstraintLowerRow
import org.gnu.glpk.GLPK; //导入依赖的package包/类
@Override
public double[] getConstraintLowerRow(ConditionalConstraint cc) {
assertIndex();
glp_prob model = getModel();
int index = GLPK.glp_find_row( model, getLowerRowLabel( cc ) );
if (index <= 0) {
return null;
}
else {
double[] coeffs = GLPKUtils.getRowCoefficients( model, index );
return coeffs;
}
}
示例8: removeColumns
import org.gnu.glpk.GLPK; //导入依赖的package包/类
@Override
public void removeColumns(String namePrefix) {
assertIndex();
SWIGTYPE_p_int delIndex = GLPK.new_intArray( getColumnNumber() );
int ind = 1;
for (int i = getFirstColumnIndex(); i <= getColumnNumber(); i++) {
String colName = GLPK.glp_get_col_name( getModel(), i );
if (colName != null && colName.startsWith( namePrefix )) {
GLPK.intArray_setitem( delIndex, ind++, i );
}
}
if (ind > 1) {
GLPK.glp_del_cols( getModel(), ind - 1, delIndex );
}
GLPK.delete_intArray( delIndex );
getSimplexCtrl().setPresolve( GLPKConstants.GLP_ON );
}
示例9: setLowerBoundingRow
import org.gnu.glpk.GLPK; //导入依赖的package包/类
@Override
public void setLowerBoundingRow() {
assertIndex();
if (GLPK.glp_find_row( getModel(), L_ROW ) <= 0) {
try {
double[] row = new double[getColumnNumber()];
Arrays.fill( row, 1d );
addRow( row, 1d, LPSolver.ROW_TYPE.GREATER_EQUAL, L_ROW );
} catch( CPException e ) {
m_logger.fatal( e );
throw new RuntimeException( e );
}
}
}
示例10: setUpperBoundingRow
import org.gnu.glpk.GLPK; //导入依赖的package包/类
@Override
public void setUpperBoundingRow() {
assertIndex();
if (GLPK.glp_find_row( getModel(), U_ROW ) <= 0) {
try {
double[] row = new double[getColumnNumber()];
Arrays.fill( row, -1d );
addRow( row, -1d, LPSolver.ROW_TYPE.GREATER_EQUAL, U_ROW );
} catch( CPException e ) {
m_logger.fatal( e );
throw new RuntimeException( e );
}
}
}
示例11: addColumn
import org.gnu.glpk.GLPK; //导入依赖的package包/类
/**
* @param column
* @throws CPException
*/
@Override
public int addColumn(double[] column, String name) throws CPException {
int index = GLPK.glp_add_cols( m_model, 1 );
//Add objective coefficient
GLPK.glp_set_obj_coef( m_model, index, column[0] );
//Set column's coefficients
GLPKUtils.setColumnCoefficients( m_model, index, column );
if (name != null) GLPK.glp_set_col_name( m_model, index, name );
return index;
}
示例12: setObjective
import org.gnu.glpk.GLPK; //导入依赖的package包/类
/**
* @param objective
* @throws CPException
*/
@Override
public void setObjective(double[] objective) throws CPException {
for (int i = 0; i < getColumnNumber(); i++) {
GLPK.glp_set_obj_coef( m_model, i + 1, i < objective.length ? objective[i] : 0d );
}
}
示例13: setModel
import org.gnu.glpk.GLPK; //导入依赖的package包/类
protected void setModel(glp_prob model) {
m_model = model;
GLPK.glp_create_index( m_model );
m_colStats = null;
m_rowStats = null;
}
示例14: dispose
import org.gnu.glpk.GLPK; //导入依赖的package包/类
public void dispose() {
if (m_model != null) {
GLPK.glp_delete_prob( m_model );
m_model = null;
m_colStats = null;
m_rowStats = null;
}
}
示例15: removeColumns
import org.gnu.glpk.GLPK; //导入依赖的package包/类
@Override
public void removeColumns(int[] indexes) throws CPException {
SWIGTYPE_p_int ind = GLPK.new_intArray( indexes.length + 1 );
for (int i = 0; i < indexes.length; i++) {
GLPK.intArray_setitem( ind, i + 1, indexes[i] );
}
GLPK.glp_del_cols( m_model, indexes.length, ind );
GLPK.delete_intArray( ind );
m_simplexCtrl.setPresolve( GLPKConstants.GLP_ON );
}