> For the complete documentation index, see [llms.txt](https://swonh.gitbook.io/sdmp-user-manual-eng/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://swonh.gitbook.io/sdmp-user-manual-eng/general-module/user-controls/logcontrol.md).

# LogControl

### GetStateLogPeriod

```csharp
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)

```csharp
public override int GetStateLogPeriod()
{
    return 5000;
}
```

### WriteSolution

```csharp
public override void WriteSolution(Solution solution)
```

#### Definition

Record the solution obtained by solver.

#### Example

```csharp
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

```csharp
 public override bool IsExportStateLog()
```

#### Definition

Sets whether to export the state log to a file.

#### Return

<table><thead><tr><th width="169.33333333333331">Type</th><th width="348">Description</th><th>Default</th></tr></thead><tbody><tr><td>Boolean</td><td>Whether to export state logs.</td><td>False</td></tr></tbody></table>

#### Example

```csharp
public override bool IsExportStateLog() 
{
    return false;
}
```

### WriteBestSolutionLog

```csharp
public override void WriteBestSolutionLog()
```

#### Definition

Write a log for the best solution.

#### Example

```csharp
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

```csharp
public override void WriteOptimalLog()
```

#### Definition

Write a log for the optimal solution.

#### Example

```csharp
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

```csharp
public override void WritePruneLog(State state)
```

#### Definition

Write a log when the state is pruned.

#### Example

```csharp
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);
}
```

{% hint style="info" %}
Since the state may often be pruned, it is recommended not to record logs unless there is a special reason.
{% endhint %}
