##Declare parameters and set and read data form input files #Read general data such as global budget constraint set G; table set_g IN "CSV" "general.csv": G<- [Setting]; param GeneralSetting{g in G}, symbolic; table GeneralSetting_g IN "CSV" "general.csv": [Setting], GeneralSetting ~ Value; #Read the locations and locations data set J; table set_j IN "CSV" "locations.csv": J<- [Location]; param LocationBudget{j in J}, symbolic; table LocationBudget_j IN "CSV" "locations.csv": [Location], LocationBudget ~ Budget; param LocationPenalty{j in J}; table LocationPenalty_j IN "CSV" "locations.csv": [Location], LocationPenalty ~ Penalty; #Read the types of demand set T; table set_t IN "CSV" "types.csv": T<- [Type]; #Read the workers list and workers data set I; table set_i IN "CSV" "workers.csv": I<- [Worker]; param WorkerType{i in I}, symbolic; table WorkerType_i IN "CSV" "workers.csv": [Worker], WorkerType ~ Type; param WorkerSalary{i in I}; table WorkerSalary_i IN "CSV" "workers.csv": [Worker], WorkerSalary ~ Salary; param WorkerFixedLoc{i in I}, symbolic; table WorkerFixedLoc_i IN "CSV" "workers.csv": [Worker], WorkerFixedLoc ~ FixedLocation; param WorkerFixed{i in I}; table WorkerFixed_i IN "CSV" "workers.csv": [Worker], WorkerFixed ~ Fixed; param WorkerOnlyPref{i in I}; table WorkerOnlyPref_i IN "CSV" "workers.csv": [Worker], WorkerOnlyPref ~ OnlyPreferences; #Read demand data param Demand{j in J, t in T}; table Demand_jt IN "CSV" "demand.csv": [Location,Type], Demand ~ Demand; #Read the list of preferences for the workers set Preference_set, dimen 2; param Weight{(i,j) in Preference_set}; table Weigth_ij IN "CSV" "preferences.csv": Preference_set <-[Worker,Location], Weight ~ Weight; ## Declare the decision variables. Only those variables that can be used are declared. var x{i in I, j in J: (WorkerFixed[i]<>0 and WorkerFixedLoc[i]=j) or (WorkerFixed[i]=0 and WorkerOnlyPref[i]<>0 and (i,j) in Preference_set) or (WorkerFixed[i]=0 and WorkerOnlyPref[i]=0)}, binary, >=0; var a{j in J, t in T}, >=0; ## Declare the objective function maximize Z: sum{(i,j) in Preference_set: WorkerFixed[i]=0}(Weight[i,j]*x[i,j]) - (sum{j in J, t in T}(LocationPenalty[j]*(1-a[j,t]))) ; ## Declare the model's constraints s.t. fixedlocation{i in I, j in J: (WorkerFixed[i]<>0 and WorkerFixedLoc[i]=j)}: x[i,j]=1; s.t. upperboundalpha{j in J, t in T}: a[j,t]<=1; s.t. onelocation{i in I}: sum{j in J: (WorkerFixed[i]<>0 and WorkerFixedLoc[i]=j) or (WorkerFixed[i]=0 and WorkerOnlyPref[i]<>0 and (i,j) in Preference_set) or (WorkerFixed[i]=0 and WorkerOnlyPref[i]=0)}x[i,j]<=1; s.t. budgetlimit{j in J: LocationBudget[j] <>'NA'}: sum{i in I: (WorkerFixed[i]<>0 and WorkerFixedLoc[i]=j) or (WorkerFixed[i]=0 and WorkerOnlyPref[i]<>0 and (i,j) in Preference_set) or (WorkerFixed[i]=0 and WorkerOnlyPref[i]=0)}x[i,j]*WorkerSalary[i]<=LocationBudget[j]; s.t. totalbudgetlimit{g in G: g= 'totalbudget' and GeneralSetting['totalbudget'] <>'NA'}: sum{i in I, j in J: (WorkerFixed[i]<>0 and WorkerFixedLoc[i]=j) or (WorkerFixed[i]=0 and WorkerOnlyPref[i]<>0 and (i,j) in Preference_set) or (WorkerFixed[i]=0 and WorkerOnlyPref[i]=0)}x[i,j]*WorkerSalary[i]<=GeneralSetting['totalbudget']; s.t. limitdemand{j in J, t in T}: sum{i in I: (WorkerFixed[i]<>0 and WorkerFixedLoc[i]=j and WorkerType[i]=t) or (WorkerFixed[i]=0 and WorkerOnlyPref[i]<>0 and (i,j) in Preference_set and WorkerType[i]=t) or (WorkerFixed[i]=0 and WorkerOnlyPref[i]=0 and WorkerType[i]=t)}x[i,j]<=Demand[j,t]; s.t. meetdemand{j in J, t in T}: sum{i in I: (WorkerFixed[i]<>0 and WorkerFixedLoc[i]=j and WorkerType[i]=t) or (WorkerFixed[i]=0 and WorkerOnlyPref[i]<>0 and (i,j) in Preference_set and WorkerType[i]=t) or (WorkerFixed[i]=0 and WorkerOnlyPref[i]=0 and WorkerType[i]=t)}x[i,j]>=a[j,t]*Demand[j,t]; ## Solve the model solve; #Create output files with the model's results printf:"">"results_x.csv"; for{i in I, j in J: ((WorkerFixed[i]<>0 and WorkerFixedLoc[i]=j) or (WorkerFixed[i]=0 and WorkerOnlyPref[i]<>0 and (i,j) in Preference_set) or (WorkerFixed[i]=0 and WorkerOnlyPref[i]=0)) and x[i,j]>0.5 }{ printf i>>"results_x.csv"; printf ",">>"results_x.csv"; printf j>>"results_x.csv"; printf "\n">>"results_x.csv"; } end;