StateControl

Controls for functions related to state

GetIntitialState

public override State GetInitialState()

Definition

Define the initial state.

Return

TypeDescriptionDefault

The initial state.

Null

Example

public override State GetInitialState()
{
    CRPData data = DataManager.Instance.Data as CRPData;
    CRPState initState = new CRPState();

    initState.SetStateInfo(data.CRPFactory.Conveyors);

    return initState;
}

GetKey

public override string GetKey(State state)

Definition

Defines the key for the state.

Parameters

TypeDescription

The state to define the key.

Return

TypeDescriptionDefault

String

The key of the state.

Example (Default Logic)

public virtual string GetKey(State state)
{
    return state.Index.ToString();
}

GetFeasibleSolution

public override Solution GetFeasibleSolution(State state)

Definition

Define the logic to find a feasible solution based on a given State.

Parameters

TypeDescription

The state to find a feasible solution.

Return

TypeDescriptionDefault

Solution

The feasible solution.

Null

Example

public override Solution GetFeasibleSolution(State state)
{           
    CRPState crpState = state as CRPState;
    CRPState copiedState = crpState.Clone();
    copiedState.IsInitial = false;

    List<CRPState> states = new List<CRPState>();
    states.AddRange(copiedState.GetBestStatesBackward().Cast<CRPState>().ToList());

    while (copiedState.JobCount > 0)
    {
        Stage stage = new Stage(copiedState.Stage.Index + 1);
        copiedState.Stage = stage;

        CRPJob lastJob = copiedState.LastRetrievedJob;

        CRPConveyor sameColorConv = copiedState.GetSameColorConveyor(lastJob);

        CRPJob retrievedJob = null;
        if (sameColorConv != null)
        {
            retrievedJob = copiedState.RetrieveJob(sameColorConv.ConveyorNum);
        }
        else 
        {
            retrievedJob = copiedState.RetrieveJob();
        }

        double cost = 0;
        if (lastJob != null && lastJob.Color.ColorNumber != retrievedJob.Color.ColorNumber)
            cost = 1;

        copiedState.BestValue += cost;

        states.Add(copiedState);
        copiedState = copiedState.Clone();
    }

    Solution feasibleSol = new Solution(states);

    return feasibleSol;
}

CanPruneByOptimality

public override bool CanPruneByOptimality(State state, ObjectiveFunctionType objFuncType, double pruneTolerance)

Definition

Determines whether a given state can be pruned without loss of optimality. If the state satisfies the prune conditions, it is excluded.

Parameters

TypeDescription

The state to be judged.

ObjectiveFunctionType

The type of objective function in the problem.

Double

The tolerance used for the comparison condition when determining the optimal condition.

TypeDescriptionDefault

Boolean

True: Prunes the state. False: Do not prune the state.

Example (Default Logic)

public override bool CanPruneByOptimality(State state, ObjectiveFunctionType objFuncType, double pruneTolerance)
{
    BoundManager boundManager = BoundManager.Instance;

    double bestPrimalBound = boundManager.BestPrimalBound;
    double dualBound = state.DualBound;
    double bestValue = state.BestValue;

    double rootDualBound = boundManager.RootDualBound;

    if (objFuncType == ObjectiveFunctionType.Minimize)
    {
        if (dualBound < rootDualBound - bestValue)
            dualBound = rootDualBound - bestValue;

        if (bestPrimalBound + pruneTolerance <= bestValue + dualBound)
            return true;
        else
            return false;
    }
    else
    {
        if (dualBound > rootDualBound - bestValue)
            dualBound = rootDualBound - bestValue;

        if (bestPrimalBound >= bestValue + dualBound + pruneTolerance)
            return true;
        else
            return false;
    }
}

Last updated