Class DirectedHelper
An helper class to handle directed-aware id's with direction-aware weights.
Inheritance
Inherited Members
Namespace: System.Dynamic.ExpandoObject
Assembly: cs.temp.dll.dll
Syntax
public static class DirectedHelper
Remarks
- id = The customer id, indepedent of turns or directions.
- directedId = What happens at a customer, do we u-turn at the customer, go straight forward, backward or u-turn in the other direction.
- departureId = How we depart from a customer, do we depart 'left' or 'right'.
- arrivalId = How we arrive at a customer, do we arrive from 'left' or 'right'.
- turn = A turn:
- 0: ------X------- forward
- 1: ------X u-turn
- 2: X------- other u-turn
- 3: ------X------- backward
A directedId contains:
- id : the regular customer id.
- turn : the turn taken at that customer, the turn defines:
- arrivalId : the arrival id at that customer.
- departureId : the departure id at that customer.
Methods
AverageWeight(Single[][], Int32, Int32)
Gets the average weight from customer1 -> customer2.
Declaration
public static float AverageWeight(this float[][] weights, int id1, int id2)
Parameters
|
System.Single[][]
weights
|
|
System.Int32
id1
|
|
System.Int32
id2
|
Returns
|
System.Single
|
BuildDirectedId(Int32, Int32)
Builds a directed id.
Declaration
public static int BuildDirectedId(int id, int turn)
Parameters
|
System.Int32
id
|
|
System.Int32
turn
|
Returns
|
System.Int32
|
BuildTurn(Int32, Int32)
Builds a turn from an arrival and departure offset.
Declaration
public static int BuildTurn(int arrivalOffset, int departureOffset)
Parameters
|
System.Int32
arrivalOffset
|
|
System.Int32
departureOffset
|
Returns
|
System.Int32
|
CheapestInsert(Single[][], Single[], Int32, Int32, out Int32, out Int32)
Gets the minimum weight from customer1 -> customer2 while inserting customer2. Outputs the best departure and arrival offsets.
Declaration
public static float CheapestInsert(this float[][] weights, float[] penalties, int id1, int id2, out int departureOffset1, out int arrivalOffset2)
Parameters
|
System.Single[][]
weights
|
|
System.Single[]
penalties
|
|
System.Int32
id1
|
|
System.Int32
id2
|
|
System.Int32
departureOffset1
|
|
System.Int32
arrivalOffset2
|
Returns
|
System.Single
|
CheapestInsert(Weight[][], Weight[], Int32, Int32, ProfileMetric, out Int32, out Int32)
Gets the minimum weight from customer1 -> customer2 while inserting customer2. Outputs the best departure and arrival offsets.
Declaration
public static Weight CheapestInsert(this Weight[][] weights, Weight[] penalties, int id1, int id2, ProfileMetric metric, out int departureOffset1, out int arrivalOffset2)
Parameters
|
Weight[][]
weights
|
|
Weight[]
penalties
|
|
System.Int32
id1
|
|
System.Int32
id2
|
|
ProfileMetric
metric
|
|
System.Int32
departureOffset1
|
|
System.Int32
arrivalOffset2
|
Returns
|
Weight
|
ExtractAll(Int32, out Int32, out Int32, out Int32, out Int32)
Extracts the arrivalId, departureId, id, and turn.
Declaration
public static void ExtractAll(int directedId, out int arrivalId, out int departureId, out int id, out int turn)
Parameters
|
System.Int32
directedId
|
|
System.Int32
arrivalId
|
|
System.Int32
departureId
|
|
System.Int32
id
|
|
System.Int32
turn
|
ExtractArrivalId(Int32)
Extracts the arrival id.
Declaration
public static int ExtractArrivalId(int directedId)
Parameters
|
System.Int32
directedId
|
Returns
|
System.Int32
|
ExtractDepartureId(Int32)
Extracts the departure id.
Declaration
public static int ExtractDepartureId(int directedId)
Parameters
|
System.Int32
directedId
|
Returns
|
System.Int32
|
ExtractId(Int32)
Extracts the original customer id.
Declaration
public static int ExtractId(int directedId)
Parameters
|
System.Int32
directedId
|
Returns
|
System.Int32
|
ExtractId(Int32, out Int32)
Extracts the turn and id.
Declaration
public static int ExtractId(int directedId, out int turn)
Parameters
|
System.Int32
directedId
|
|
System.Int32
turn
|
Returns
|
System.Int32
|
ExtractOffset(Int32, out Int32, out Int32)
Extracts the arrival and departure offsets.
Declaration
public static void ExtractOffset(int turn, out int arrivalOffset, out int departureoffset)
Parameters
|
System.Int32
turn
|
|
System.Int32
arrivalOffset
|
|
System.Int32
departureoffset
|
ExtractTurn(Int32)
Extracts the turn.
Declaration
public static int ExtractTurn(int directedId)
Parameters
|
System.Int32
directedId
|
Returns
|
System.Int32
|
MinWeight(Single[][], Int32, Int32)
Gets the minimum weight from customer1 -> customer2.
Declaration
public static float MinWeight(this float[][] weights, int id1, int id2)
Parameters
|
System.Single[][]
weights
|
|
System.Int32
id1
|
|
System.Int32
id2
|
Returns
|
System.Single
|
SetWeight(Single[][], Int32, Int32, Single)
Sets the weights between two customers.
Declaration
public static void SetWeight(this float[][] weights, int id1, int id2, float weight)
Parameters
|
System.Single[][]
weights
|
|
System.Int32
id1
|
|
System.Int32
id2
|
|
System.Single
weight
|
SetWeight(Single[][], Int32, Int32, Single, Single, Single, Single)
Sets the weights between two customers.
Declaration
public static void SetWeight(this float[][] weights, int id1, int id2, float forward1forward2, float forward1backward2, float backward1forward1, float backward1backward2)
Parameters
|
System.Single[][]
weights
|
|
System.Int32
id1
|
|
System.Int32
id2
|
|
System.Single
forward1forward2
|
|
System.Single
forward1backward2
|
|
System.Single
backward1forward1
|
|
System.Single
backward1backward2
|
ShiftAfterBestTurns(Tour, Single[][], Single[], Int32, Int32)
Shifts the directed customer aft er the given directed before with the best possible turns.
Declaration
public static float ShiftAfterBestTurns(this Tour tour, float[][] weights, float[] penalties, int directedCustomer, int directedBefore)
Parameters
|
Tour
tour
|
|
System.Single[][]
weights
|
|
System.Single[]
penalties
|
|
System.Int32
directedCustomer
|
|
System.Int32
directedBefore
|
Returns
|
System.Single
|
SwitchArrivalOffset(Int32)
Switches the arrival offset.
Declaration
public static int SwitchArrivalOffset(int directedId)
Parameters
|
System.Int32
directedId
|
Returns
|
System.Int32
|
SwitchDepartureOffset(Int32)
Switches the departure offset.
Declaration
public static int SwitchDepartureOffset(int directedId)
Parameters
|
System.Int32
directedId
|
Returns
|
System.Int32
|
SwitchToBestTurn(Int32, Int32, Int32, Single[][], Single[], out Int32, out Boolean, out Boolean, out Single)
Switches the given directed id to the best turn given the before and after directed id's.
Declaration
public static bool SwitchToBestTurn(int directedId, int beforeDirectedId, int afterDirectedId, float[][] weights, float[] turnPenalties, out int betterDirectedId, out bool departureIdSwitched, out bool arrivalIdSwitched, out float delta)
Parameters
|
System.Int32
directedId
|
|
System.Int32
beforeDirectedId
|
|
System.Int32
afterDirectedId
|
|
System.Single[][]
weights
|
|
System.Single[]
turnPenalties
|
|
System.Int32
betterDirectedId
|
|
System.Boolean
departureIdSwitched
|
|
System.Boolean
arrivalIdSwitched
|
|
System.Single
delta
|
Returns
|
System.Boolean
|
UpdateArrivalOffset(Int32, Int32)
Updates the arrival offset.
Declaration
public static int UpdateArrivalOffset(int directedId, int arrivalOffset)
Parameters
|
System.Int32
directedId
|
|
System.Int32
arrivalOffset
|
Returns
|
System.Int32
|
UpdateDepartureOffset(Int32, Int32)
Updates the departure offset.
Declaration
public static int UpdateDepartureOffset(int directedId, int departureOffset)
Parameters
|
System.Int32
directedId
|
|
System.Int32
departureOffset
|
Returns
|
System.Int32
|
Weight(Tour, Single[][], Single[])
Calculates the weight of the given tour.
Declaration
public static float Weight(this Tour tour, float[][] weights, float[] turnPenalties)
Parameters
|
Tour
tour
|
|
System.Single[][]
weights
|
|
System.Single[]
turnPenalties
|
Returns
|
System.Single
|
WeightWithoutTurns(Single[][], Int32, Int32)
Calculates the weights between the two directed id's without the turn weights.
Declaration
public static float WeightWithoutTurns(this float[][] weights, int directed1, int directed2)
Parameters
|
System.Single[][]
weights
|
|
System.Int32
directed1
|
|
System.Int32
directed2
|
Returns
|
System.Single
|