程序代写 title: “Swim Relay LP”

title: “Swim Relay LP”
output: html_document

“`{r setup, include=FALSE}

Copyright By PowCoder代写 加微信 powcoder

knitr::opts_chunk$set(echo = TRUE)

library(lpSolveAPI)
setwd(“Week 3/R”)

data <- read.csv(file.choose()) swimmers <- colnames(data[, -1]) strokes <- data$Stroke decision_variables <- data.frame(assignment = apply(expand.grid(strokes, swimmers), 1, paste, collapse="_"), stroke = rep(strokes, length(swimmers)), swimmer = rep(swimmers, each = length(strokes))) decision_variables model <- make.lp(length(swimmers) + length(strokes), length(swimmers) * length(strokes)) column <- 0 for (swim in 1:length(swimmers)){ for (stroke in 1:length(strokes)){ column <- column + 1 set.column(model,column,c(1, 1), indices=c(stroke, length(strokes) + swim)) set.constr.type(model, c(rep("=",length(strokes)), rep("<=", length(swimmers)))) set.constr.value(model, rhs = rep(1, length(strokes) + length(swimmers))) times <- NULL for (s in swimmers) { times <- c(times, data[ ,s]) set.objfn(model,times ) set.type(model, c(1:nrow(decision_variables)), "binary") dimnames(model)[[2]] <- decision_variables$assignment write.lp(model, "model.lp", "lp") solve(model) min_time <- get.objective(model) assign <- get.variables(model) names(assign) <- decision_variables$assignment assign[assign == 1] 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com