如何在 Mosel 中打印结果

How to print results in Mosel

我正在尝试创建一个从 excel 文件中获取数据并涉及 20 个地区的能源需求的 mosel 模型。 每个区域都有 3 种可能的替代方案,对应于我们在模型中考虑的能源中心类型和最大容量。
每兆瓦的可变成本各不相同,我们的目标是通过最小化总成本来满足地区的总体需求。 每个地区对可以生产的能源数量都有限制。 当我尝试打印结果时,最终矩阵 (X) 以这种方式显示: "[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]" 我附上代码谢谢。

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

在您的模型中,Xmpvar 的数组。根据 documentation of write() and writeln(),对于这样的数组,仅打印元素的内存地址。这就是为什么您会看到所有这些十六进制数。

为了查看决策变量的实际值,您必须访问变量的 .sol 属性,例如

forall(r in Regions,C in Centraltype)
  writeln(X(r,C).sol)