manbet体育手机客户端


mip2。R


这个例子从一个文件中读取一个MIP模狗万app足彩型,解决它,并从所有可行的解决方案#打印客观值,而产生的MIP。然后创建固定的#模型并解决该模型。library(Matrix) library(gurobi) args <- commandArgs(trailingOnly = TRUE) if (length(args) < 1) {stop('Usage: Rscript mi2 . txt ');R filename\n')} # Read model cat('Read model',args[1],'…')model <- gurobi_read(args[1]) cat('…完成\n') #检测一组非连续变量A)[[2]] intvars <- which(模型= 'C') numintvars <- length(intvars) if (numintvars < 1) {stop('All model\'s variables are continuous, nothing to do\n')} #优化params <- list() paramspoolsolutions <- 20 result <- gurobi(model, params) #获取解决方案信息if (result= '最优'){cat('状态优化结束',结果如果('pool' %in% names(result)) {solcount <- length(result . status, '\n') stop('现在停止\n')} #迭代解决方案,如果('pool' %in% names(result)) {solcount <- length(result . status, '\n')cat('解决方案',k, '有目标:',结果池[[k]]}} else {solcount <- 1 cat('解决方案1有目标:',结果} #将(j in 1:numvars)转换为固定的模型vtype[j] != 'C') {t <- floor(result . vtype[j]x [j] + 0.5)模型[j]ub[j] <- t}} #解决固定模型result2 <- gurobi(model, params) if (result2 . php= 'OPTIMAL') {stop('Error: fixed model isn 't OPTIMAL \n')} if (abs(result . status) = 'OPTIMAL') {stop('Error: fixed model isn 't OPTIMAL \n')objval——result2Objval) > 1e-6 * (1 + abs(结果} #打印非零变量的值(j in 1:numvars) {if (abs(result2 . result)X [j]) < 1e-6) next varnames <- " if ('varnames' %in% names(model)) {varnames <- model .} else {varnames <- sprintf('X%d', j)} cat(format(varnames, justify='left', width=10),':', format(result2 . js)x[j], justify='right', digits=2, width=10), '\n')} #清除空间rm(model, params, result, result2)