LogControl

Controls for functions related to logging

GetStateLogPeriod

public override int GetStateLogPeriod()

Definition

Sets the frequency at which state logs are collected. For example, if set to 5000, logs will be collected once every 5000 states.

Example (Default Logic)

public override int GetStateLogPeriod()
{
    return 5000;
}

WriteSolution

public override void WriteSolution(Solution solution)

Definition

Record the solution obtained by solver.

Example

public override void WriteSolution(Solution solution)
{
    StringBuilder jobStr = new StringBuilder();
    StringBuilder colorStr = new StringBuilder();
    StringBuilder convStr = new StringBuilder();

    IOrderedEnumerable<KeyValuePair<int, State>> states = solution.States.OrderBy(x => x.Key);

    foreach (KeyValuePair<int, State> item in states)
    {
        CRPState state = item.Value as CRPState;

        if (state.IsInitial)
            continue;

        jobStr.Append(state.LastRetrievedJob.Number);
        colorStr.Append(state.LastRetrievedJob.Color.ColorNumber);
        convStr.Append(state.CurrentConveyor.ConveyorNum);

        if (state.JobCount > 0)
        {
            jobStr.Append("-");
            colorStr.Append("-");
            convStr.Append("-");
        }
    }

    Console.WriteLine(string.Format("Job Sequence: {0}", jobStr.ToString()));
    Console.WriteLine(string.Format("Color Sequence: {0}", colorStr.ToString()));
    Console.WriteLine(string.Format("Conveyor Sequence: {0}", convStr.ToString()));
}

IsExportStateLog

 public override bool IsExportStateLog()

Definition

Sets whether to export the state log to a file.

Return

TypeDescriptionDefault

Boolean

Whether to export state logs.

False

Example

public override bool IsExportStateLog() 
{
    return false;
}

WriteBestSolutionLog

public override void WriteBestSolutionLog()

Definition

Write a log for the best solution.

Example

public override void WriteBestSolutionLog()
{
    SolutionManager solutionManager = SolutionManager.Instance;
    Solution bestSol = solutionManager.BestSolution;

    Console.WriteLine(Constants.LINE);
    Console.WriteLine(string.Format("Objective Value: {0}", bestSol.Value));
    this.WriteSolution(bestSol);
    Console.WriteLine(Constants.LINE);
}

WriteOptimalLog

public override void WriteOptimalLog()

Definition

Write a log for the optimal solution.

Example

public override void WriteOptimalLog()
{
    SolutionManager solutionManager = SolutionManager.Instance;
    Solution optSol = solutionManager.OptimalSolution;

    Console.WriteLine(Constants.LINE);
    Console.WriteLine(string.Format("Optimal Objective Value: {0}", optSol.Value));
    this.WriteSolution(optSol);
    Console.WriteLine(Constants.LINE);
}

WritePruneLog

public override void WritePruneLog(State state)

Definition

Write a log when the state is pruned.

Example

public override void WritePruneLog(State state)
{
    Console.WriteLine("Prune => StateIndex:{0}, State:{1}, Stage:{2}, DualBound:{3}, BestValue:{4}, BestPrimalBound:{5}", state.Index, state.ToString(), state.Stage.Index, state.DualBound, state.BestValue, BoundManager.Instance.BestPrimalBound);
}

Since the state may often be pruned, it is recommended not to record logs unless there is a special reason.

Last updated