• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java GLPK类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.gnu.glpk.GLPK的典型用法代码示例。如果您正苦于以下问题:Java GLPK类的具体用法?Java GLPK怎么用?Java GLPK使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



GLPK类属于org.gnu.glpk包,在下文中一共展示了GLPK类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
 
开发者ID:KeepTheBeats,项目名称:alevin-svn2,代码行数:20,代码来源:LpSolver.java


示例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;
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:17,代码来源:GLPKLPSolverImpl.java


示例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 );
		}			
	}
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:25,代码来源:GLPKLPSolverImpl.java


示例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 );		
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:18,代码来源:GLPKUtils.java


示例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;
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:20,代码来源:GLPKUtils.java


示例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 );
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:19,代码来源:GLPKUtils.java


示例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;
	}
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:17,代码来源:CCAwareGLPKSolver.java


示例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 );
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:24,代码来源:CCAwareGLPKSolver.java


示例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 );
		}
	}
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:20,代码来源:CCAwareGLPKSolver.java


示例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 );
		}
	}
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:20,代码来源:CCAwareGLPKSolver.java


示例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;
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:18,代码来源:GLPKLPSolverImpl.java


示例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 );
	}
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:12,代码来源:GLPKLPSolverImpl.java


示例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;
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:8,代码来源:GLPKLPSolverImpl.java


示例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;
	}
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:11,代码来源:GLPKLPSolverImpl.java


示例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 );
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:15,代码来源:GLPKLPSolverImpl.java


示例16: testVarAssignment

import org.gnu.glpk.GLPK; //导入依赖的package包/类
public boolean testVarAssignment(double[] assignment) {
	
	SWIGTYPE_p_int varIndexes = GLPK.new_intArray( GLPK.glp_get_num_cols( m_model ) + 1 );
	SWIGTYPE_p_double row = GLPK.new_doubleArray( GLPK.glp_get_num_cols( m_model ) + 1 );
	boolean result = true;
	
	/*try {
		writeLP( "C:\\kl\\tmp\\test.lp" );
	} catch( IOException e ) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}*/
	
	//Check it row by row
	for (int rowIndex = 1; result && (rowIndex <= GLPK.glp_get_num_rows( m_model )); rowIndex++) {
		
		int len = GLPK.glp_get_mat_row( m_model, rowIndex, varIndexes, row );
		int type = GLPK.glp_get_row_type( m_model, rowIndex );
		double lb = GLPK.glp_get_row_lb( m_model, rowIndex );
		double ub = GLPK.glp_get_row_ub( m_model, rowIndex );
		//Check the inequality
		if (len > 0) result &= checkRow(row, varIndexes, len, type, lb, ub, assignment);
	}
	
	GLPK.delete_intArray( varIndexes );
	GLPK.delete_doubleArray( row );
	
	return result;
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:30,代码来源:GLPKLPSolverImpl.java


示例17: checkRow

import org.gnu.glpk.GLPK; //导入依赖的package包/类
private boolean checkRow(	SWIGTYPE_p_double row,
							SWIGTYPE_p_int varIndexes,
							int len,
							int type,
							double lb,
							double ub,
							double[] assignment) {
	
	//Compute left hand-side first
	double lhs = 0d;
	boolean result = false;
	
	for (int i = 1; i <= len; i++) {
		
		int varInd = GLPK.intArray_getitem(varIndexes, i);
		double coeff = GLPK.doubleArray_getitem(row, i);
		
		lhs += coeff * assignment[varInd - 1];
	}
	
	if (type == GLPKConstants.GLP_FX) {
		
		result = NumberUtils.equal(lhs, lb);
	}
	
	if (type == GLPKConstants.GLP_LO) {
		
		result = !NumberUtils.greater(lb, lhs);
	}
	
	if (type == GLPKConstants.GLP_UP) {
		
		result = !NumberUtils.greater(lhs, ub);
	}		
	
	return result;
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:38,代码来源:GLPKLPSolverImpl.java


示例18: getStatus

import org.gnu.glpk.GLPK; //导入依赖的package包/类
@Override
public STATUS getStatus() {

	int status = GLPK.glp_get_status( m_model );		
	
	if (status == GLPKConstants.GLP_OPT) return STATUS.OPTIMAL;
	if (status == GLPKConstants.GLP_FEAS) return STATUS.FEASIBLE;
	if (status == GLPKConstants.GLP_NOFEAS) return STATUS.INFEASIBLE;

	return STATUS.UNDEFINED;
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:12,代码来源:GLPKLPSolverImpl.java


示例19: getStatus

import org.gnu.glpk.GLPK; //导入依赖的package包/类
@Override
public STATUS getStatus() {

	int simplexStatus = GLPK.glp_get_status( getModel() );		
	int mipStatus = GLPK.glp_mip_status( getModel());
	
	if (mipStatus == GLPKConstants.GLP_OPT) return STATUS.OPTIMAL;
	if (mipStatus == GLPKConstants.GLP_FEAS) return STATUS.FEASIBLE;
	if (mipStatus == GLPKConstants.GLP_NOFEAS 
			|| simplexStatus == GLPKConstants.GLP_NOFEAS) return STATUS.INFEASIBLE;

	return STATUS.UNDEFINED;
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:14,代码来源:GLPKMIPSolverImpl.java


示例20: initMIPInstance

import org.gnu.glpk.GLPK; //导入依赖的package包/类
public void initMIPInstance(MIPSolver.VAR_TYPE[] varTypes) {
	
	super.initLPInstance( varTypes.length);
	//The rest is to set proper column types
	for (int i = 0; i < varTypes.length; i++) {
		
		GLPK.glp_set_col_kind(getModel(), i+1,  GLPKUtils.genericColumnTypeToGLPKType(varTypes[i]));
	}		
}
 
开发者ID:klinovp,项目名称:pronto,代码行数:10,代码来源:GLPKMIPSolverImpl.java



注:本文中的org.gnu.glpk.GLPK类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ObjectSerializer类代码示例发布时间:2022-05-22
下一篇:
Java NMMemoryStateStoreService类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap