I am attempting to create a mosel model that takes data from an excel file and concerns energy demand for 20 regions.
Each region has 3 possible alternatives corresponding to the kind of energy centrals we're considering in the model and a maximum of capacity.
Centrals differ for variable costs per mw and our goal is to cover the overall demand of the regions by minimizing total costs.
Each region has a constraint regarding the quantity of energy that can produce.
When I try to print the results the final matrix (X) it appear in that way:
"[0x7fd85a85ea70,0x7fd85a85ea80,0x7fd85a85ea90,0x7fd85a85eaa0,0x7fd85a85eab0,0x7fd85a85eac0,0x7fd85a85ead0,0x7fd85a85eae0,0x7fd85a85eaf0,0x7fd85a85eb00,0x7fd85a85eb10,0x7fd85a85eb20,0x7fd85a85eb30,0x7fd85a85eb40,0x7fd85a85eb50,0x7fd85a85eb60,0x7fd85a85eb70,0x7fd85a85eb80,0x7fd85a85eb90,0x7fd85a85eba0,0x7fd85a85ebb0,0x7fd85a85ebc0,0x7fd85a85ebd0,0x7fd85a85ebe0,0x7fd85a85ebf0,0x7fd85a85ec00,0x7fd85a85ec10,0x7fd85a85ec20,0x7fd85a85ec30,0x7fd85a85ec40,0x7fd85a85ec50,0x7fd85a85ec60,0x7fd85a85ec70,0x7fd85a85ec80,0x7fd85a85ec90,0x7fd85a85eca0,0x7fd85a85ecb0,0x7fd85a85ecc0,0x7fd85a85ecd0,0x7fd85a85ece0,0x7fd85a85ecf0,0x7fd85a85ed00,0x7fd85a85ed10,0x7fd85a85ed20,0x7fd85a85ed30,0x7fd85a85ed40,0x7fd85a85ed50,0x7fd85a85ed60,0x7fd85a85ed70,0x7fd85a85ed80,0x7fd85a85ed90,0x7fd85a85eda0,0x7fd85a85edb0,0x7fd85a85edc0,0x7fd85a85edd0,0x7fd85a85ede0,0x7fd85a85edf0,0x7fd85a85ee00,0x7fd85a85ee10,0x7fd85a85ee20]"
I attach code thank you.
uses "mmxprs","mmsheet"!optimization library, Excel library
! Declaration of parameters used in the model
parameters
FileTo="mmsheet.xlsx:noindex;last.xlsx" !Excel file with the input data
end-parameters
setparam("XPRS_VERBOSE",true); !Activate xpress verbose.
setparam("XPRS_MAXTIME", 60) !Setting maximum search time to 1 hour=3600 seconds
declarations
N:integer; !Number of REGIONS to consider
Cent:integer; !DIFFERENT CENTRALS
totdemand: integer;
end-declarations
initializations from FileTo
N as "[Regions$A1]" !Read this value from the Excel file in sheet CityNumber cell A1
Cent as "[Centrals$A1]"
totdemand as "[Demand$B23]"
end-initializations
declarations
Regions=1..N;
Centraltype= 1..Cent;
maxproductible: array(Regions) of real;
Demand: array(Regions) of real; !expected demand from each city
costtype: array(Centraltype) of real;
RegionName: array(Regions) of string;!city names
!NCentraltype: array(Centraltype) of string;
maxcapacity: array(Regions,Centraltype) of real;
X: array(Regions,Centraltype) of mpvar; !capacity produced
!y:array(Centrals,Regions) of mpvar; !binary variable that assigns warehouse to city of customers in MODEL 0
!continuous variable that count homw many coustomeres of a city are served by a warehouse
ObjectiveFunction: linctr;
end-declarations
initializations from FileTo
!Distance as "[Distance$B3:U22]"
Demand as "[Demand$B1:B20]"
RegionName as "[Demand$A1:A20]"
!NCentraltype as "[Centrals$G9:G11]"
costtype as "[Centrals$F3:F5]"
maxproductible as "[Demand$F1:F20]"
end-initializations
procedure Modelllll
totcost:=sum(r in Regions,C in Centraltype) X(r,C)*costtype(C)
forall (r in Regions, C in Centraltype) X(r,C) <= maxcapacity(r,C)
forall (r in Regions) sum(C in Centraltype) X(r,C)<= maxproductible(r)
forall (r in Regions) sum(C in Centraltype) X(r,C) >= totdemand
minimise(totcost)
end-procedure
! Print out the solution
writeln("Total setup times: ", getobjval)
forall(r in Regions,C in Centraltype)
end-model