Loading [MathJax]/extensions/tex2jax.js
MinchinWeb's MetaLibrary  v.9
Library functions of OpenTTD AI writers.
All Classes Files Functions Variables Enumerations Enumerator Pages
_MinchinWeb_Atlas_ Class Reference

Keep track of the world – match sources and destinations. More...

Public Member Functions

function GetVersion ()
 
function GetRevision ()
 
function GetDate ()
 
function GetName ()
 
function Reset ()
 Resets the Atlas. More...
 
function AddSource (Source, Priority)
 Adds a source to the sources list with the given priority. More...
 
function AddAttraction (Attraction, Priority)
 Adds an attraction to the attraction list with the given priority. More...
 
function AddBoth (AddedTile, Priority)
 Adds to both sources and attractions. More...
 
function RunModel ()
 Runs the Atlas. More...
 
function Pop ()
 Pop the heap. More...
 
function Peek ()
 Peek the heap. More...
 
function Count ()
 Number of pairs in the heap. More...
 
function Exists ()
 Check if an item exists in the heap. More...
 
function SetModel (newmodel)
 Set the model type. More...
 
function GetModel ()
 Returns the current model type. More...
 
function PrintModelType (ToPrint)
 The string equivalent of the ModelType. More...
 
function SetMaxDistance (distance=-1)
 Set the maximum distance the model will allow. More...
 
function SetMaxDistanceModel (newmodel)
 Set the ModelType for determining max distance. More...
 

Static Public Member Functions

function ApplyTrafficModel (StartTile, StartPriority, EndTile, EndPriority, Model)
 Apply the Atlas model. More...
 

Private Member Functions

 constructor ()
 

Private Attributes

 _heap_class = import("Queue.Binary_Heap", "", 1)
 
 _sources = []
 'From' here... (array) More...
 
 _attractions = []
 'To' here (array) More...
 
 _pairs = null
 Heap of paired sources and attractions. More...
 
 _ignorepairs = []
 A list of pairs to ignore. More...
 
 _maxdistance = null
 This is the maximum distance between sources and attractions to include in the model. More...
 
 _maxdistancemodel = null
 This is how to measure distances between sources and attractions to determine weather they exceed "_maxdistance". More...
 
 _model = null
 Stores models selected, see ModelType. More...
 

Detailed Description

Keep track of the world – match sources and destinations.

Version
v.1 (2012-01-28)
Author
W. Minchin (MinchinWeb)
Since
MetaLibrary v.2

The Atlas takes sources (departs) and attractions (destinations) and then generates a heap of pairs sorted by rating. I use this class to decide which pairs of industries or towns to service.

Ratings can be generated based on distance alone or can be altered by user defined ratings (e.g. industry productions or town populations).

Depends On:
Binary Heap v.1
Depends On:
ModelType

Definition at line 99 of file Atlas.nut.

Member Function Documentation

function _MinchinWeb_Atlas_::AddAttraction ( Attraction  ,
Priority   
)
inline

Adds an attraction to the attraction list with the given priority.

Parameters
AttractionAssumed to be a TileIndex.

Definition at line 150 of file Atlas.nut.

function _MinchinWeb_Atlas_::AddBoth ( AddedTile  ,
Priority   
)

Adds to both sources and attractions.

Adds a tile to the BOTH the sources list and the attractions list with the (same) given priority.

Parameters
AddedTileAssumed to be a TileIndex.

Definition at line 263 of file Atlas.nut.

function _MinchinWeb_Atlas_::AddSource ( Source  ,
Priority   
)
inline

Adds a source to the sources list with the given priority.

Parameters
SourceAssumed to be a TileIndex.

Definition at line 142 of file Atlas.nut.

function _MinchinWeb_Atlas_::ApplyTrafficModel ( StartTile  ,
StartPriority  ,
EndTile  ,
EndPriority  ,
Model   
)
static

Apply the Atlas model.

Given the start and end tiles, applies the traffic model and returns the weighting. Smaller weightings are considered better.

Note
This function is independent of the model/class (i.e. it is a static function), so is useful if you want to apply the traffic model to a given set of tiles. It is what is called internally to apply the model.
Parameters
StartTileAssumed to be a TileId
StartPriorityPriority (weighting) assigned to Start
EndTileAssumed to be a TileId
EndPriotityPriority (weighting) assigned to End
ModelAssumed to be one of the enum ModelType

Definition at line 340 of file Atlas.nut.

_MinchinWeb_Atlas_::constructor ( )
inlineprivate

Definition at line 123 of file Atlas.nut.

function _MinchinWeb_Atlas_::Count ( )
inline

Number of pairs in the heap.

Returns
Number of pairs in the heap.

Definition at line 186 of file Atlas.nut.

function _MinchinWeb_Atlas_::Exists ( )
inline

Check if an item exists in the heap.

Returns
True or False

Definition at line 191 of file Atlas.nut.

function _MinchinWeb_Atlas_::GetDate ( )
inline

Definition at line 104 of file Atlas.nut.

function _MinchinWeb_Atlas_::GetModel ( )
inline

Returns the current model type.

Returns
The current model type, as the enum.
See also
ModelType

Definition at line 202 of file Atlas.nut.

function _MinchinWeb_Atlas_::GetName ( )
inline

Definition at line 105 of file Atlas.nut.

function _MinchinWeb_Atlas_::GetRevision ( )
inline

Definition at line 103 of file Atlas.nut.

function _MinchinWeb_Atlas_::GetVersion ( )
inline

Definition at line 102 of file Atlas.nut.

function _MinchinWeb_Atlas_::Peek ( )
inline

Peek the heap.

Returns
The top rated pair as an array.
Note
Leaves the pair in the model.
See also
Pop()

Definition at line 181 of file Atlas.nut.

function _MinchinWeb_Atlas_::Pop ( )

Pop the heap.

Returns
The top rated pair as an array.
Warning
Removes the pair from the model.
See also
Peek()

Definition at line 286 of file Atlas.nut.

function _MinchinWeb_Atlas_::PrintModelType ( ToPrint  )

The string equivalent of the ModelType.

Parameters
ToPrintModelType, as enum
Returns
The string equivalent.
See also
ModelType

Definition at line 311 of file Atlas.nut.

function _MinchinWeb_Atlas_::Reset ( )

Resets the Atlas.

Dumps all entered data.

Definition at line 251 of file Atlas.nut.

function _MinchinWeb_Atlas_::RunModel ( )

Runs the Atlas.

Takes the provided sources and destinations and runs the selected traffic model, populating the 'pairs' heap.

Definition at line 269 of file Atlas.nut.

function _MinchinWeb_Atlas_::SetMaxDistance ( distance  = -1)

Set the maximum distance the model will allow.

Parameters
distanceSets the maximum distance between sources and attractions to be included in the model. Negative values remove the limit.
See also
SetMaxDistanceModel()

Definition at line 370 of file Atlas.nut.

function _MinchinWeb_Atlas_::SetMaxDistanceModel ( newmodel  )

Set the ModelType for determining max distance.

Used to calculate the distance between the source and attraction for applying maxdistance.

Parameters
newmodelModelType to use
Note
For newmodel, ModelType .DISTANCE_NONE is invalid. Use SetMaxDistance(-1) instead.
For newmodel, ModelType .ONE_OVER_T_SQUARED is invalid.
See also
SetMaxDistance()

Definition at line 380 of file Atlas.nut.

function _MinchinWeb_Atlas_::SetModel ( newmodel  )

Set the model type.

See also
ModelType

Definition at line 301 of file Atlas.nut.

Member Data Documentation

_MinchinWeb_Atlas_::_attractions = []
private

'To' here (array)

Definition at line 113 of file Atlas.nut.

_MinchinWeb_Atlas_::_heap_class = import("Queue.Binary_Heap", "", 1)
private

Definition at line 110 of file Atlas.nut.

_MinchinWeb_Atlas_::_ignorepairs = []
private

A list of pairs to ignore.

Definition at line 116 of file Atlas.nut.

_MinchinWeb_Atlas_::_maxdistance = null
private

This is the maximum distance between sources and attractions to include in the model.

Definition at line 117 of file Atlas.nut.

_MinchinWeb_Atlas_::_maxdistancemodel = null
private

This is how to measure distances between sources and attractions to determine weather they exceed "_maxdistance".

Definition at line 118 of file Atlas.nut.

_MinchinWeb_Atlas_::_model = null
private

Stores models selected, see ModelType.

Definition at line 121 of file Atlas.nut.

_MinchinWeb_Atlas_::_pairs = null
private

Heap of paired sources and attractions.

Definition at line 114 of file Atlas.nut.

_MinchinWeb_Atlas_::_sources = []
private

'From' here... (array)

Definition at line 112 of file Atlas.nut.


The documentation for this class was generated from the following file: