> 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/approximationcontrol.md).

# ApproximationControl

Controls for functions related to state space approximation

### IsApplyStateFiltering

```csharp
public override bool IsApplyStateFiltering()
```

#### Definition

Defines whether to filter the state to be explored. There are two types of logic for filtering states:&#x20;

* **Global filtering:** filters on states in stages.
* **Local filtering:** filters on state transitions.

#### Return

<table><thead><tr><th width="160">Type</th><th width="385">Description</th><th>Default</th></tr></thead><tbody><tr><td>Boolean</td><td>Whether to apply state filtering logic.</td><td>False</td></tr></tbody></table>

#### Example (Default Logic)

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

### IsApplyApproximation

```csharp
public override bool IsApplyApproximation()
```

#### Definition

Whether to apply the approximation method to filter the states during global filtering.

#### Return

<table><thead><tr><th width="148">Type</th><th width="455">Description</th><th>Default</th></tr></thead><tbody><tr><td>Boolean</td><td>Whether to apply approximation logic to global filtering.</td><td>False</td></tr></tbody></table>

#### Example (Default Logic)

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

### IsUseEstimationValue

```csharp
public override bool IsUseEstimationValue()
```

#### Definition

Set whether to calculate and utilize value estimates in states.

#### Return

<table><thead><tr><th width="163.33333333333331">Type</th><th width="378">Description</th><th>Default</th></tr></thead><tbody><tr><td>Boolean</td><td>True: Apply<br>False: Do not apply</td><td>False</td></tr></tbody></table>

#### Example (Default Logic)

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

### GetEstimationValueUpdatePeriod

```csharp
public override int GetEstimationValueUpdatePeriod()
```

#### Definition

Sets the frequency at which the value estimate is calculated for a state. In other words, if that frequency is *n*, then every *n*th state, the value estimate for the state is calculated.

#### Return

<table><thead><tr><th width="129.33333333333331">Type</th><th width="363">Description</th><th>Default</th></tr></thead><tbody><tr><td>Integer</td><td>The frequency at which the value estimate of the state is calculated.</td><td>1</td></tr></tbody></table>

#### Example (Default Logic)

```csharp
public override int GetEstimationValueUpdatePeriod()
{
    return 1;
}
```

### GetEstimationValueStopStageIndex

```csharp
public override int GetEstimationValueStopStageIndex()
```

#### Definition

Set the stage index at which to stop calculating the estimated value of the state. In other words, if the value is *n* and the stage Index is greater than *n*, the state value estimate is not calculated.

#### Return

<table><thead><tr><th width="112.33333333333331">Type</th><th width="465">Description</th><th>Default</th></tr></thead><tbody><tr><td>Integer</td><td>The stage index at which to start calculating the estimated value of the state.</td><td>Int32.MaxValue</td></tr></tbody></table>

#### Example (Default Logic)

```csharp
public override int GetEstimationValueStopStageIndex()
{
    return Int32.MaxValue;
}
```

### GetStateFilteringType

```csharp
public override StateFilteringType GetStateFilteringType()
```

#### Definition

Set up logic to filter the states to explore.

#### Return

| Type                 | Description           | Default                           |
| -------------------- | --------------------- | --------------------------------- |
| `StateFilteringType` | State filtering type. | [Default Logic](#default-logic-2) |

#### Example (Default Logic)

```csharp
public override StateFilteringType GetStateFilteringType()
{
    return StateFilteringType.Global;
}
```

### GetGlobalTransitionCount

```csharp
public override int GetGlobalTransitionCount()
```

#### Definition

Sets the number of states to explore when applying global filtering. For example, if you set the value to 1000, only 1000 states will remain in the stage, and the remaining states will be excluded.

#### Definition

<table><thead><tr><th width="129">Type</th><th width="433">Description</th><th>Default</th></tr></thead><tbody><tr><td>Integer</td><td>The number of states to explore after global filtering.</td><td>1000</td></tr></tbody></table>

#### Example (Default Logic)

```csharp
public override int GetGlobalTransitionCount()
{
    return 1000;
}
```

### GetApproximationTransitionCount

```csharp
public override int GetApproximationTransitionCount() 
```

#### Definition

Sets the number of states to explore when applying global filtering using the approximation method. For example, if you set the value to 1000, only 1000 states will remain in the stage, and the remaining states will be excluded.

#### Return

<table><thead><tr><th width="111.33333333333331">Type</th><th width="479">Description</th><th>Default</th></tr></thead><tbody><tr><td>Integer</td><td>The number of states to explore after global filtering using the approximation method.</td><td>10</td></tr></tbody></table>

#### Example (Default Logic)

```csharp
public override int GetApproximationTransitionCount() 
{
    return 10;
}
```

### GetClusterTransitionCount

```csharp
public override int GetClusterTransitionCount()
```

#### Definition

Sets the number of states to explore when applying global filtering using the state clustering method.  For example, if you set the value to 10, only 10 states will remain in the stage, and the remaining states will be excluded.

#### Return

<table><thead><tr><th width="135.33333333333331">Type</th><th width="497">Description</th><th>Default</th></tr></thead><tbody><tr><td>Integer</td><td>The number of states to explore after global filtering using the state clustering method.</td><td>2</td></tr></tbody></table>

#### Example (Default Logic)

```csharp
public override int GetClusterTransitionCount() 
{
    return 2;
}
```

### GetLocalTransitionCount

```csharp
public override int GetLocalTransitionCount()
```

#### Definition

Sets the number of states to explore when applying local filtering. For example, if you set the value to 1, only 1 of the state transitions from a state will be selected to navigate to the next state defined in that transition.

#### Return

<table><thead><tr><th width="138">Type</th><th width="433">Description</th><th>Default</th></tr></thead><tbody><tr><td>Integer</td><td>The number of states to explore after local filtering.</td><td>1</td></tr></tbody></table>

#### Example (Default Logic)

```csharp
public override int GetLocalTransitionCount()
{
    return 1;
}
```

### GetGlobalFilteringStartStageIndex

```csharp
public override int GetGlobalFilteringStartStageIndex()
```

#### Definition

Sets the stage index to start applying the global filtering logic. For example, if you set this value to 0, the global filtering logic will be applied to all stages with an Index greater than or equal to 0.

#### Return

<table><thead><tr><th width="121">Type</th><th width="473">Description</th><th>Default</th></tr></thead><tbody><tr><td>Integer</td><td>The stage index to start applying the global filtering logic.</td><td>0</td></tr></tbody></table>

#### Example (Default Logic)

```csharp
public override int GetGlobalFilteringStartStageIndex()
{
    return 0;
}
```

### GetLocalFilteringStartStageIndex

```csharp
public override int GetLocalFilteringStartStageIndex()
```

#### Definition

Sets the stage index to start applying the local filtering logic. For example, if you set this value to 0, the local filtering logic will be applied to all stages with an Index greater than or equal to 0.

#### Return

<table><thead><tr><th width="126">Type</th><th width="472">Description</th><th>Default</th></tr></thead><tbody><tr><td>Integer</td><td>The stage index to start applying the local filtering logic.</td><td>0</td></tr></tbody></table>

#### Example (Default Logic)

```csharp
public override int GetLocalFilteringStartStageIndex()
{
    return 0;
}
```

### GetApproximationStartStageIndex

```csharp
public override int GetApproximationStartStageIndex()
```

#### Definition

Sets the stage index to start applying the global filtering logic using approximation method. For example, if you set this value to 0, the approximation method will be applied to all stages with an Index greater than or equal to 0.

#### Return

<table><thead><tr><th width="123">Type</th><th width="467">Description</th><th>Default</th></tr></thead><tbody><tr><td>Integer</td><td>The stage index to start applying the global filtering logic using approximation method.</td><td>0</td></tr></tbody></table>

#### Example (Default Logic)

```csharp
public override int GetApproximationStartStageIndex()
{
    return 0;
}
```

### GetMinimumTransitionCost

```csharp
public override double GetMinimumTransitionCost()
```

#### Definition

Sets the smallest transition cost for all possible transitions. This value is a parameter used to filter the states to be explored by the approximation method.

#### Return

<table><thead><tr><th width="116">Type</th><th width="451">Description</th><th>Default</th></tr></thead><tbody><tr><td>Integer</td><td>The smallest possible transition cost.</td><td>0</td></tr></tbody></table>

#### Example (Default Logic)

```csharp
public override double GetMinimumTransitionCost()
{
    return 0;
}
```

### GetMultiplier

```csharp
public override double GetMultiplier()
```

#### Definition

This parameter is used to filter the states to be explored by the approximation method. The higher the value, the more states will be explored, increasing computation time and potentially improving the objective function value.

#### Return

<table><thead><tr><th width="172">Type</th><th width="341">Description</th><th>Default</th></tr></thead><tbody><tr><td>Double</td><td>The value of the multiplier parameter.</td><td>2</td></tr></tbody></table>

#### Example (Default Logic)

```csharp
public override double GetMultiplier() 
{
    return 2;
}
```

### GetEstimatedValue

```csharp
public override double GetEstimatedValue(State state)
```

#### Definition

Sets an estimate of the value function of a given state. This estimate is used to apply approximation method to reduce the number of states to explore.

#### Parameters

<table><thead><tr><th width="238">Type</th><th>Description</th></tr></thead><tbody><tr><td>State</td><td>The state to compute the value function estimate.</td></tr></tbody></table>

#### Return

<table><thead><tr><th width="122">Type</th><th width="393">Description</th><th>Default</th></tr></thead><tbody><tr><td>Double</td><td>An estimate of the value function of the state.</td><td><a href="#default-logic-10">Default Logic</a></td></tr></tbody></table>

#### Example (Default Logic)

```csharp
public override double GetEstimatedValue(State state)
{
    double dualBound = BoundControl.Instance.GetDualBound(state);
    state.SetDualBound(dualBound);

    return state.BestValue + state.DualBound;
}
```

### FilterGlobalStates

```csharp
public override List<State> FilterGlobalStates(List<State> states, int maxTransitionCount, ObjectiveFunctionType objectiveFunctionType, double pruneTolerance, bool isApplyStateClustering)
```

#### Definition

Defines the global filtering logic and returns a list of states to explore.

#### Parameters

<table><thead><tr><th width="235">Type</th><th>Description</th></tr></thead><tbody><tr><td>List&#x3C;State></td><td>The list of states before filtering.</td></tr><tr><td>Integer</td><td>The maximum number of states to explore after filtering.</td></tr><tr><td>ObjectiveFunctionType</td><td>The type of objective function in the problem. (Maximize, Minimize)</td></tr><tr><td>Double</td><td>The tolerance value that is applied when determining the state pruning condition.</td></tr><tr><td>Boolean</td><td>Whether to apply state clustering method.</td></tr></tbody></table>

#### Return

<table><thead><tr><th width="155">Type</th><th width="435">Description</th><th>Default</th></tr></thead><tbody><tr><td>List&#x3C;State></td><td>The list of states to explore after global filtering.</td><td><a href="#default-logic-11">Default Logic</a> </td></tr></tbody></table>

#### Example (Default Logic)

```csharp
public override List<State> FilterGlobalStates(List<State> states, int maxTransitionCount, ObjectiveFunctionType objectiveFunctionType, double pruneTolerance, bool isApplyStateClustering)
{
    List<State> filtered = new List<State>();

    if (isApplyStateClustering)
    {
        Dictionary<int, List<State>> clusters = new Dictionary<int, List<State>>();
        foreach (State state in states)
        {
            if (clusters.TryGetValue(state.ClusterID, out List<State> list) == false)
            {
                clusters.Add(state.ClusterID, new List<State>() { state });
            }
            else 
            {
                list.Add(state);
            }
        }

        int clusterTransitionCount = this.GetClusterTransitionCount();
        foreach (KeyValuePair<int, List<State>> item in clusters)
        {
            List<State> list = item.Value.OrderBy(x => x.ClusterDistance).ToList();

            int maxCount = clusterTransitionCount;
            int count = 0;
            foreach (State st in list)
            {
                if (count > maxCount)
                    break;

                filtered.Add(st);

                count++;
            }
        }
    }
    else
    {
        foreach (State state in states)
        {
            if (state.IsFinal)
                continue;

            double estimatedValue = GetEstimatedValue(state);
            state.EstimationValue = estimatedValue;
        }

        if (objectiveFunctionType == ObjectiveFunctionType.Minimize)
            states = states.OrderBy(x => x.EstimationValue).ToList();
        else if (objectiveFunctionType == ObjectiveFunctionType.Maximize)
            states = states.OrderByDescending(x => x.EstimationValue).ToList();

        int count = 0;
        foreach (State state in states)
        {
            if (maxTransitionCount <= count)
                break;

            filtered.Add(state);
            count++;
        }
    }

    return filtered;
}
```

### FilterLocalStates

```csharp
public override List<State> FilterLocalStates(List<State> states, int maxTransitionCount)
```

#### Definition

Defines the local filtering logic and returns a list of states to explore.

#### Parameters

<table><thead><tr><th width="234">Type</th><th>Description</th></tr></thead><tbody><tr><td>List&#x3C;State></td><td>The list of states before filtering.</td></tr><tr><td>Integer</td><td>The maximum number of states to explore after filtering.</td></tr></tbody></table>

#### Return

<table><thead><tr><th width="152">Type</th><th width="404">Description</th><th>Default</th></tr></thead><tbody><tr><td>List&#x3C;State></td><td>The list of states to explore after local filtering.</td><td><a href="#default-logic-12">Default Logic</a></td></tr></tbody></table>

#### Example (Default Logic)

```csharp
public override List<State> FilterLocalStates(List<State> states, int maxTransitionCount)
{
    states = states.OrderBy(x => x.PrevBestState.DualBound + (x.BestValue - x.PrevBestState.BestValue) + x.BestValue).ToList();

    List<State> filtered = new List<State>();

    int count = 0;
    foreach (State state in states)
    {
        if (maxTransitionCount <= count)
            break;

        filtered.Add(state);
        count++;
    }

    return filtered;
}
```

### CanPruneByApproximation

```csharp
public override bool CanPruneByApproximation(State state, ObjectiveFunctionType objFuncType, double minEstimationValue, double minTransitionCost, double multiplier, double pruneTolerance)
```

#### Definition

Sets whether a given state should be excluded from exploration when reducing the number of states to explore via approximation methods.

#### Parameters

<table><thead><tr><th width="238">Type</th><th width="510">Description</th></tr></thead><tbody><tr><td>State</td><td>The state to be evaluated.</td></tr><tr><td>ObjectiveFunctionType</td><td>The type of objective function in the problem. (Maximize, Minimize)</td></tr><tr><td>Double</td><td>The smallest of the value function estimates of the candidate states to explore.</td></tr><tr><td>Double</td><td>The smallest possible transition cost.</td></tr><tr><td>Double</td><td>The value of the multiplier parameter.</td></tr><tr><td>Double</td><td>The tolerance value that is applied when determining the state pruning condition.</td></tr></tbody></table>

#### Return

<table><thead><tr><th width="129">Type</th><th width="392">Description</th><th>Default</th></tr></thead><tbody><tr><td>Boolean</td><td>Whether to prune the state.</td><td><a href="#default-logic-13">Default Logic</a></td></tr></tbody></table>

#### Example (Default Logic)

```csharp
 public override bool CanPruneByApproximation(State state, ObjectiveFunctionType objFuncType, double minEstimationValue, double minTransitionCost, double multiplier, double pruneTolerance)
{
    if (state.IsFinal)
        return false;

    if (objFuncType == ObjectiveFunctionType.Minimize)
    {
        if (state.EstimationValue + pruneTolerance > minEstimationValue + (minTransitionCost * multiplier))
            return true;
        else
            return false;
    }
    else
    {
        if (state.EstimationValue + pruneTolerance < minEstimationValue + (minTransitionCost * multiplier))
            return true;
        else
            return false;
    }
}
```
