代码中的问题:线性编程-R或Lingo

时间:2019-04-01 05:18:36

标签: r linear-programming lingo

问题:

================================================ ===============

Lingo语言:

MODEL:

MIN = 35.91 * 300 * gt_1 + 58.55 * 514 * gt_2 + 684 * def;

gt_1 + gt_2 + def + ghu = 1200;
va + vt + vv  = 8607.04;
-0.2275 * vt + ghu = 0;

@bnd(7000, va, 12540); !interval;
@bnd(0, vt, 6412.97);  !interval;
@bnd(0, ghu, 1458.86); !interval;
@bin(gt_1); !binary;
@bin(gt_2); !binary;
END

================================================ ==========

R语言:

##########################
####     PROBLEM    #####
##########################

lprec = lpSolveAPI::make.lp(4,8)

f = -0.2275

lpSolveAPI::set.column(lprec, 1, c(1, 0, 0, 0))
lpSolveAPI::set.column(lprec, 2, c(1, 0, 0, 0))
lpSolveAPI::set.column(lprec, 3, c(1, 0, 0, 0))
lpSolveAPI::set.column(lprec, 4, c(1, 0, 1, 0))
lpSolveAPI::set.column(lprec, 5, c(0, 1, 0, 0))
lpSolveAPI::set.column(lprec, 6, c(0, 1, f, 0))
lpSolveAPI::set.column(lprec, 7, c(0, 1, 0, 0))
lpSolveAPI::set.column(lprec, 8, c(0, 0, 0, 1))

lpSolveAPI::set.objfn(lprec, c(35.91 * 300, 58.55 * 514, 684, 0, 0, 0, 0, 1))

lpSolveAPI::set.constr.type(lprec, c("=","=","=","="))

alpha = 0
BH = 8607.04

lpSolveAPI::set.rhs(lprec, c(1200, BH, 0, alpha))
lpSolveAPI::set.type(lprec, 1, "binary")
lpSolveAPI::set.type(lprec, 2, "binary")

fator = 2.6784
eng = 2394.33 * fator

lpSolveAPI::set.bounds(lprec, lower = c(0, 7000, 0), columns = c(4, 5, 6))
lpSolveAPI::set.bounds(lprec, upper = c(1458.86, 12540, eng), columns = c(4, 5, 6))


RowNames = c("Demanda","BH", "Producao", "alpha")
ColNames = c("GT_1", "GT_2", "Def", "Ghu", "Va", "Vt", "Vv", "alpha")

dimnames(lprec) = list(RowNames, ColNames)

minimizar = lpSolveAPI::lp.control(lprec, sense = c("min"))

lprec
##########################
####     SOLUCION     #####
##########################
solucao.problema4 = lpSolveAPI::solve.lpExtPtr(lprec)
solucao.problema4
##########################
####    OUTCOME   #####
##########################
lpSolveAPI::get.objective(lprec)
lpSolveAPI::get.variables(lprec)
lpSolveAPI::get.constraints(lprec)

================================================

Ps .:忽略Alpha。

我在R和Lingo中做过,结果是:

GT_1      0.000000            
GT_2      0.000000          
DEF       834.3984      
GHU       365.6016      
VA        7000.000         
VT        1607.040           
VV        0000.000 

目标值= 570728.5

但是根据材料,答案是:

GT_1      1            
GT_2      1         
DEF       20.4000      
GHU       365.600      
VA        7000.00         
VT        1607.04           
VV        0000.00 

目标值= 54820.21

++++++++++++++++++++++++++++++++++++++++++++++ < / p>

错误在哪里?

0 个答案:

没有答案