如何使用;新的(……)”;在Julia中的类型定义内部?
我正在阅读一段代码,对类型声明中新方法的使用感到困惑 通过搜索互联网,我了解了内部构造函数和外部构造函数的含义,我知道这是Julia中新方法的主要用途,如下链接:如何使用;新的(……)”;在Julia中的类型定义内部?,julia,Julia,我正在阅读一段代码,对类型声明中新方法的使用感到困惑 通过搜索互联网,我了解了内部构造函数和外部构造函数的含义,我知道这是Julia中新方法的主要用途,如下链接: 我的困惑主要如下。新方法中提供的值的数量小于类型声明中的字段数量。有人能给我解释一下吗 您可以使用少于字段数的参数调用new,以获得未完全初始化的对象 正如Julia手册的章节所解释的,这是有意的 这对于可变结构非常有用(引用手册): 内部构造函数方法可以将不完整的对象传递给其他函数以委托其完成: type GenConfig
我的困惑主要如下。新方法中提供的值的数量小于类型声明中的字段数量。有人能给我解释一下吗 您可以使用少于字段数的参数调用
new
,以获得未完全初始化的对象
正如Julia手册的章节所解释的,这是有意的
这对于可变结构非常有用(引用手册):
内部构造函数方法可以将不完整的对象传递给其他函数以委托其完成:
type GenConfig
outputPath::String
mode::String # "all" or "calls"
# output file names
ambsFilename::String
arcsFilename::String
callsFilename::String
hospitalsFilename::String
mapFilename::String
nodesFilename::String
prioritiesFilename::String
stationsFilename::String
travelFilename::String
# counts
numAmbs::Int
numCalls::Int
numHospitals::Int
numStations::Int
# graph
xNodes::Int # number of nodes in x direction
yNodes::Int # number of nodes in y direction
# map
map::Map
mapTrim::Float # fraction of map border to trim, to make sure objects generated on map are inside borders
# misc
startTime::Float
targetResponseTime::Float
offRoadSpeed::Float
stationCapacity::Int
travelModeSpeeds::Vector{Float}
# call density raster
callDensityRasterFilename::String
cropRaster::Bool
callRasterCellSeed::Int # seed for rng, will generate raster cell index
callRasterCellLocSeed::Int # seed for rng, will generate location within raster cell
# call related distributions and random number generators
interarrivalTimeDistrRng::DistrRng
priorityDistrRng::DistrRng
dispatchDelayDistrRng::DistrRng
onSceneDurationDistrRng::DistrRng
transferDistrRng::DistrRng
transferDurationDistrRng::DistrRng
# misc RNGs
ambStationRng::AbstractRNG
callLocRng::AbstractRNG
hospitalLocRng::AbstractRNG
stationLocRng::AbstractRNG
travelTimeFactorDistrRng::DistrRng
GenConfig() = new("", "",
"", "", "", "", "", "", "", "", "",
nullIndex, nullIndex, nullIndex, nullIndex,
nullIndex, nullIndex,
Map(), 1e-6,
nullTime, nullTime, nullTime, nullIndex, [],
"", false, nullIndex, nullIndex)
end
julia> mutable struct Lazy
data
Lazy(v) = complete_me(new(), v)
end