Yes sorry I have read that already, but my code was really long so I wasn’t sure how to summarize it, but I managed to make an MWE out of it.
#add the 4 packages that will be used
using JuMP, GLPK, CSV, DataFrames
#CSV file containing file directories (in 2 columns because 2 files per loop)
Input_Files = CSV.File("C:\\Users\\Muadh\\.atom\\Input files.csv", header = false) |> DataFrame
#arrange the data from the input CSV files into dataframes
Df1 = DataFrame.(CSV.File.(Input_Files[!,:Column1]))
Df2 = DataFrame.(CSV.File.(Input_Files[!,:Column2]))
for i = 1:size(Input_Files, 2)
#create the model
m = Model(with_optimizer(GLPK.Optimizer))
#Assign input parameters from input files, create decision variables
g = Df1[i][1,2]
@objective(m, Min, π)
#create constraints and objective function
con_rev, ρ == π * g
#create solution dataframe of decision variables...
#send this dataframe to a .csv file
CSV.write("Solution Table$i.csv", df)
I tried to shorten it as much as possible, so I apologise if it is not exactly an MWE. But I’ll do what you suggested about putting it in a function. Forgive my ignorance, but I’m curious as to what exactly are the benefits of using a function instead of just a for loop?
Also, I think the
for loop in your example uses only one file per loop, if I’m not mistaken? How would I do it for n files per loop? In my case n is equal to 2.