R语言-最优化_整数规划、线性规划求解(Rsymphony)

来源:互联网 发布:员工管理系统 java 编辑:程序博客网 时间:2024/06/06 00:09

Rsymphony包简介

Rsymphony,混合整数线性规划SYMPHONY 求解器,其中主函数有:

Rsymphony_solve_LP(obj, mat, dir, rhs, bounds = NULL,                    types = NULL, max = FALSE, verbosity = -2,                    time_limit = -1, node_limit = -1, gap_limit = -1,                    first_feasible = FALSE,                   write_lp = FALSE, write_mps = FALSE)
主要参数 作用 obj 规划目标系数 mat 约束向量矩阵 dir 约束方向向量,有’>’、’<’、’=’构成 rhs 约束值 bounds 上下限的约束,默认0到INF type 限定目标变量的类型,’B’指的是0-1规划,’C’代表连 max 逻辑值,T为求最大值,F为最小值

example

example1

min(z=3x1+1x2+3x3)3x1+4x2+2x3<=602x1+x2+x3<=40x1+3x2+2x3<=80x1,x2,x3

# 求解library(Rsymphony)obj <- c(2, 4, 3)mat <- matrix(c(3, 2, 1, 4, 1, 3, 2, 1, 2), nrow = 3)#      [,1] [,2] [,3]#[1,]    3    4    2#[2,]    2    1    1#[3,]    1    3    2dir <- c("<=", "<=", "<=")rhs <- c(60, 40, 80)max <- FRsymphony_solve_LP(obj, mat, dir, rhs, max = max)#$solution#[1]  0  0 30#$objval#[1] 90#$status                    # 0表有解,1表找不到解#TM_OPTIMAL_SOLUTION_FOUND #                        0 

example2

max(3x1+1x2+3x3)1x1+2x2+x3<=44x23x3<=2x13x2+2x3<=3x1,x3x2

obj <- c(3, 1, 3)mat <- matrix(c(-1, 0, 1, 2, 4, -3, 1, -3, 2), nrow = 3)#      [,1] [,2] [,3]#[1,]   -1    2    1#[2,]    0    4   -3#[3,]    1   -3    2dir <- c("<=", "<=", "<=")rhs <- c(4, 2, 3)max <- TRUEtypes <- c("I", "C", "I")Rsymphony_solve_LP(obj, mat, dir, rhs, types = types, max = max)#$solution#[1] 5.00 2.75 3.00#$objval#[1] 26.75#$status#TM_OPTIMAL_SOLUTION_FOUND #                        0 
0 0
原创粉丝点击