# 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://swonh.gitbook.io/sdmp-user-manual-eng/general-module/user-controls/logcontrol.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
