What package could I use to get all the iterations of the simplex algorithm when solving a linear program in R?
I want to solve a linear program in R with the simplex algorithm. However, rather than just getting the final optimal solution, I also want to get all the iterations that the simplex algorithm goes through. What package could I use to get all the iterations of the simplex algorithm when solving a linear program in R?
See also questions close to this topic

Run Rscript from a path with spaces, on Windows (only)
Similar to this question, I'd like to run a Rscript from a Windows folder with spaces. I'm using R version 3.5.0, and I've added the executables on my
PATH
. Here's what I have from cmd.exe:c:\>cat "C:\Temp\New folder\test.R" message("Hello") c:\>Rscript "C:\Temp\New folder\test.R" Fatal error: cannot open file 'C:\Temp\New': No such file or directory c:\>Rscript C:/Temp/New\ folder/test.R Fatal error: cannot open file 'C:/Temp/New\': No such file or directory
So it seems that Rscript has difficulty with paths to files with spaces. Is there a simple workaround?
A few notes to consider:
 I can't rename the folder with spaces. If that were possible, this wouldn't be an issue.
 This seems to be a Windows issue, as I can't recreate this on Linux
 I'd prefer not to
cd /d "C:\Temp\New folder"
thenRscript test.R
, as I ultimately want to process some data in a different directory than where the script is.

Recalculate a column in data.frame
Coming from Python + Pandas, I tried to convert a column in an R data.frame.
In Python/Pandas I'd do it like so:
df[['weight']] = df[['weight']] / 1000
In R I came up with this:
convertWeight < function(w) { return(w/1000) } df$weight < lapply(df$weight, convertWeight)
I know of the library
dplyr
which has the functionmutate
. That would allow me to transform columns as well.Is there a different way to mutate a column without using the
dplyr
library? Something that comes close toPandas
way of doing it? 
Check whether an ID's classifier/attribute changes from one month to the next and if it does, create a list of changes
I have a data.frame with a "DATE" column, an "ID" column and a "CLASSIFIER" column, as follows:
Data < data.frame( DATE = sample(seq(as.Date("20100201"), length=12, by="1 month")  1,50,replace = TRUE), ID = sample(1:9,50,replace = TRUE), CLASSIFIER = sample(c("yes", "no"), 50, replace = TRUE) )
The output looks like this:
DATE ID CLASSIFIER 1 20100331 3 yes 2 20100430 3 no 3 20100430 4 no 4 20100630 9 yes 5 20100930 2 no 6 20101130 5 no
I would now like to get a list of those IDs whose classifier changes from one date to the next. In other words, I want a list of all IDs (including the respective date) which change from
"yes"
to"no"
or from"no"
to"yes"
from one month to the next. Ideally, the list would also state the nature of the change (i.e. from"no"
to"yes"
or from"yes"
to"no"
) From the output example above (first two lines), if ID "3" has the"yes"
CLASSIFIER
on 20100331 and the"no"
CLASSIFIER
on 20100430, the list should state ID "3", "20100430" and something like "yes to no".Would someone please help me with this?
Thank you very much in advance for your help!
Kind regards,
C.

Linear programming conditional constraint
There are 22 drivers. Each driver has to work min of 7.6 hrs and can work max of 10 hrs. Each driver cost and productivity is different.
if some driver works overtime (more than 7.6 hrs), for first 2 hrs, we need to pay 1.5 times. For remaining 0.4 hrs, we need to pay 2 times.
195 hrs of work has to be completed by 22 drivers. We need to schedule in such a way that cost can be minimized.
Driver,Cost,Productivity A,70,0.8 B,22,0.8 C,24,0.8 D,26,0.8 E,28,0.8 F,30,0.8 G,32,0.8 H,34,0.8 I,36,0.8 J,38,0.8 K,40,0.8 L,42,0.9 M,44,0.9 N,46,0.9 O,48,0.9 P,50,0.9 Q,52,0.9 R,54,0.9 S,56,0.9 T,58,0.9 U,60,0.9 V,62,0.5
Decision Variables:
X1,X2 ........X22 represents the total number of hours allocated to each driver
Objective Function:
Min Z = 20*X1 +22*X2......62*X22
Constraints:
X1>=7.6,X2>=7.6....X22>=7.6
X1<=10,X2<=10....X22<=10
X1+X2.....+X22 <= 195
I have tried following python program so far.
import pulp import pandas as pd def main(): model = pulp.LpProblem("Cost minimising scheduling problem", pulp.LpMinimize) totalHours = 192 minHourEachDriver = 7.6 maxHourEachDriver = 10 # importing data from CSV drivers = pd.DataFrame.from_csv('csv/drivers.csv', index_col=['Driver', 'Cost', 'Productivity']) # Decision Variables drv = pulp.LpVariable.dicts("driverName", indexs=((i) for i, j, k in drivers.index), lowBound=0, cat='Continuous') # Objective model += pulp.lpSum([j * (1 / k) * drv[i] for i, j, k in drivers.index]), "Cost" # Constraints # total no of hours work to be done model += pulp.lpSum([drv[i] for i, j, k in drivers.index]) == totalHours for i, j, k in drivers.index: # minimum hours driver has to work model += drv[i] >= minHourEachDriver # Maximum hour driver can work model += drv[i] <= maxHourEachDriver model.solve() # model status print(pulp.LpStatus[model.status]) # Total Cost print(pulp.value(model.objective)) # No of hrs allocated to each driver for i, j, k in drivers.index: var_value = drv[i].varValue # print(var_value) print("The number hours for driver {0} are {1}".format(i, var_value)) if __name__ == '__main__': main()
But, I am not able to figure out, how do we put following constraint.
if some driver work overtime (more than 7.6 hrs), for first 2 hrs, we need to pay 1.5 times. For remaining 0.4 hrs, we need to pay 2 times.

Comparing the results from lpSolve to linprog, is it a problem in implementation?
I would like to minimize a linear programming system with linear constraints "equalities".
The system summarized in the following code "Python 3"
>>> obj_func = [1,1,1] >>> const = [[[1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 1, 1]]] >>> constraints= np.reshape(const, (1, 3)) >>> constraints array([[1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 1, 1]]) >>> rhs = [0.4498162176582741, 0.4498162176582741, 0.10036756468345168, 1.0]
Using
scipy.optimization.linprg
:>>> res = linprog(obj_func, constraints, rhs, method="interiorpoint", options={"disp":True}) >>> res con: array([], dtype=float64) fun: 1.4722956444515663e09 message: 'Optimization terminated successfully.' nit: 4 slack: array([0.44981622, 0.44981622, 0.10036756, 1. ]) status: 0 success: True x: array([4.34463075e10, 4.34463075e10, 6.03369494e10])
The same system summarized in R and minimized using
lpSolve
:> obj.func = c(1,1,1) > constraints = matrix(c(1,0,0,0,1,0,0,0,1,1,1,1), nrow= 4, byrow = TRUE) > rhs = c(0.4498162+0i, 0.4498162+0i, 0.1003676+0i, 1.0000000+0i) > f.dir = c("=","=","=","=") > > res = lp("min",obj.func,constraints,f.dir,rhs,compute.sens=FALSE) > res Success: the objective function is 1
As detailed above, the results are not close to each other although it is the same system so I did the same work for other systems but the results are also far.
My question: I know it is not necessary that every LP has a unique solution but I think they should produce close values ! In my case, I tried to minimize many systems using both solvers but the results are too far. For example,
First system: linprog gave 1.4722956444515663e09 while lpSolve gave 1 Another system: linprog gave 1.65952852061376e11 while lpSolve gave 0.8996324 Another system: linprog gave 3.05146726445553e12 while lpSolve gave 0.8175745

GLOP C# decimal places on each step of calculus
I'm using ORTools from Google to solve a GLOP linear programming problem similar to Stigler diet.
I need that the solver use 3 decimal places on each step of calculus.
Should I create a
Constraint
with this rule? How?