> For the complete documentation index, see [llms.txt](https://swonh.gitbook.io/sdmp-user-manual-kor/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-kor/general-module/undefined-1/approximationcontrol.md).

# ApproximationControl

### IsApplyStateFiltering

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

#### 정의

탐색할 State를 필터링할지 여부를 정의합니다. State를 필터링하는 로직은 State Transition을 필터링하는 Local 필터링과 Stage의 State를 대상으로 필터링하는 Global 필터링이 있습니다.

#### 반환

<table><thead><tr><th width="160">Type</th><th width="385">Description</th><th>Default</th></tr></thead><tbody><tr><td>Boolean</td><td>State 필터링 로직 적용 여부입니다.</td><td>False</td></tr></tbody></table>

#### 예제 (Default Logic)

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

### IsApplyApproximation

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

#### 정의

근사해를 구하는 로직을 적용할 지 여부를 설정합니다.

#### 반환

<table><thead><tr><th width="148">Type</th><th width="327">Description</th><th>Default</th></tr></thead><tbody><tr><td>Boolean</td><td>근사해를 구하는 로직 적용 여부입니다.</td><td>False</td></tr></tbody></table>

#### 예제 (Default Logic)

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

### IsUseEstimationValue

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

#### 정의

State에서 가치 추정값을 계산하고 활용할지 여부를 설정합니다.

#### 반환

<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: 적용<br>False: 미적용</td><td>False</td></tr></tbody></table>

#### 예제 (Default Logic)

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

### GetEstimationValueUpdatePeriod

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

#### 정의

State에서 가치 추정 값을 계산하는 주기를 설정합니다. 즉, 해당 주기가 n일 경우 n번째 State마다 State의 가치 추정 값을 계산합니다.

#### 반환

<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>State의 가치 추정 값을 계산하는 주기입니다.</td><td>1</td></tr></tbody></table>

#### 예제 (Default Logic)

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

### GetEstimationValueStopStageIndex

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

#### 정의

State의 가치 추정 값을 계산을 중단할 Stage Index를 설정합니다. 즉, 해당 값이 n일 경우 Stage Index가 n 이상일 경우 State 가치 추정 값을 계산하지 않습니다.

#### 반환

<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>State 가치 추정 값 계산 중단을 시작할 Stage Index입니다.</td><td>Int32.MaxValue</td></tr></tbody></table>

#### 예제 (Default Logic)

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

### GetStateFilteringType

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

#### 정의

탐색할 State를 필터링하는 로직을 설정합니다.

#### 반환

| Type               | Description      | Default                              |
| ------------------ | ---------------- | ------------------------------------ |
| StateFilteringType | State 필터링 타입입니다. | [Default Logic 참조](#default-logic-2) |

#### 예제 (Default Logic)

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

### GetGlobalTransitionCount

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

#### 정의

Global 필터링 적용 시, 필터링 후 최종 탐색을 진행할 State 개수를 설정합니다. 예를 들어, 해당 값을 1000으로 설정할 경우, 특정 Stage에서 1000개의 State만 남기고 나머지 State는 탐색대상에서 제외합니다.

#### 반환

<table><thead><tr><th width="129">Type</th><th width="433">Description</th><th>Default</th></tr></thead><tbody><tr><td>Integer</td><td>Global 필터링 후 탐색을 진행할 State 개수입니다.</td><td>1000</td></tr></tbody></table>

#### 예제 (Default Logic)

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

### GetApproximationTransitionCount

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

#### 정의

근사 로직을 통한 Global 필터링 적용 시, 필터링 후 최종 탐색을 진행할 최대 State 개수를 설정합니다. 예를 들어, 해당 값을 1000으로 설정할 경우, 특정 Stage에서 최대 1000개의 State만 남기고 나머지 State는 탐색 대상에서 제외합니다.

#### 반환

<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>근사 로직을 사용한 Global 필터링 후 탐색을 진행할 최대 State 개수입니다.</td><td>10</td></tr></tbody></table>

#### 예제 (Default Logic)

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

### GetClusterTransitionCount

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

#### 정의

State Clustering 방법을 사용한 Global 필터링 적용 시, 필터링 후 최종 탐색을 진행할 State 개수를 설정합니다. 예를 들어, 해당 값을 10으로 설정할 경우, 특정 Stage에서 10개의 State만 남기고 나머지 State는 탐색대상에서 제외합니다.

#### 반환

<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>State Clustering 방법을 사용한 Global 필터링 후 탐색을 진행할State 개수입니다.</td><td>2</td></tr></tbody></table>

#### 예제 (Default Logic)

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

### GetLocalTransitionCount

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

#### 정의

Local 필터링 적용 시, 필터링 후 최종 탐색을 진행할 State 개수를 설정합니다. 예를 들어, 해당 값을 1으로 설정할 경우, 특정 State로부터의 State Transition 중 1개만 선택하여 해당 State Transition에 정의된 다음 State를 탐색합니다.

#### 반환

<table><thead><tr><th width="138">Type</th><th width="408">Description</th><th>Default</th></tr></thead><tbody><tr><td>Integer</td><td>Local 필터링 후 탐색을 진행할 State 개수입니다.</td><td>1</td></tr></tbody></table>

#### 예제 (Default Logic)

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

### GetGlobalFilteringStartStageIndex

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

#### 정의

Global 필터링 로직을 적용을 시작할 Stage Index를 설정합니다. 예를 , 해당 값을 0으로 설정할 경우 Index가 0보다 크거나 같은 Stage에 모두 Global 필터링 로직이 적용됩니다.

#### 반환

<table><thead><tr><th width="121">Type</th><th width="438">Description</th><th>Default</th></tr></thead><tbody><tr><td>Integer</td><td>Global 필터링 로직 적용을 시작할 Stage Index 입니다.</td><td>0</td></tr></tbody></table>

#### 예제 (Default Logic)

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

### GetLocalFilteringStartStageIndex

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

#### 정의

Local 필터링 로직을 적용을 시작할 Stage Index를 설정합니다. 예를 들어, 해당 값을 0으로 설정할 경우 Index가 0보다 크거나 같은 Stage에 모두 Local 필터링 로직이 적용됩니다.

#### 반환

<table><thead><tr><th width="126">Type</th><th width="448">Description</th><th>Default</th></tr></thead><tbody><tr><td>Integer</td><td>Local 필터링 로직 적용을 시작할 Stage Index 입니다.</td><td>0</td></tr></tbody></table>

#### 예제 (Default Logic)

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

### GetApproximationStartStageIndex

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

#### 정의

근사해를 구하는 로직 적용을 시작할 Stage의 Index를 설정합니다. 예를 들어, 해당 값을 0으로 설정할 경우 Index가 0보다 크거나 같은 Stage에 모두 근사해를 구하는 로직이 적용됩니다.

#### 반환

<table><thead><tr><th width="123">Type</th><th width="467">Description</th><th>Default</th></tr></thead><tbody><tr><td>Integer</td><td>근사해를 구하는 로직 적용을 시작할 Stage의 Index 입니다. </td><td>0</td></tr></tbody></table>

#### 예시 (Default Logic)

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

### GetMinimumTransitionCost

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

#### 정의

가능한 모든 Transition에 대하여 가장 작은 Transition cost를 설정합니다. 해당 값은 근사 로직을 통해 탐색할 State를 필터링할 때 사용되는 파라메터 입니다.

#### 반환

<table><thead><tr><th width="116">Type</th><th width="451">Description</th><th>Default</th></tr></thead><tbody><tr><td>Integer</td><td>발생 가능한 가장 작은 Transition cost 입니다.</td><td>0</td></tr></tbody></table>

#### 예제 (Default Logic)

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

### GetMultiplier

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

#### 정의

근사 로직을 통해 탐색할 State를 필터링 할 때 사용되는 파라메터 입니다. 해당 값이 클수록 많은 State를 탐색하며 계산시간이 증가하고 목적함수 값이 개선될 가능성이 높아집니다.

#### 반환

<table><thead><tr><th width="172">Type</th><th width="341">Description</th><th>Default</th></tr></thead><tbody><tr><td>Double</td><td>Multiplier 파라메터 값 입니다.</td><td>2</td></tr></tbody></table>

#### 예제 (Default Logic)

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

### GetEstimatedValue

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

#### 정의

주어진 State의 가치함수 (Value function)의 추정치를 설정합니다. 해당 추정치는 근사 로직을 적용하여 탐색할 State 수를 줄이는데 사용됩니다.

#### 매개 변수

<table><thead><tr><th width="238">Type</th><th>Description</th></tr></thead><tbody><tr><td>State</td><td>가치함수 (Value function)의 추정치를 구할 대상 State 입니다.</td></tr></tbody></table>

#### 반환

<table><thead><tr><th width="192">Type</th><th width="324">Description</th><th>Default</th></tr></thead><tbody><tr><td>Double</td><td>State의 가치함수 추정치 입니다.</td><td><a href="#default-logic-10">Default Logic 참조</a></td></tr></tbody></table>

#### 예제 (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)
```

#### 정의

Global 필터링 로직을 정의하고 이를 통해 탐색할 State 리스트를 반환합니다.

#### 매개 변수

<table><thead><tr><th width="235">Type</th><th>Description</th></tr></thead><tbody><tr><td>List&#x3C;State></td><td>필터링 하기 전 State 리스트 입니다.</td></tr><tr><td>Integer</td><td>필터링 후 탐색을 진행할 최대 State 수 입니다.</td></tr><tr><td>ObjectiveFunctionType</td><td>문제의 목적함수 타입입니다. (Maximize, Minimize)</td></tr><tr><td>Double</td><td>State Prune 조건 판단 시 적용되는 Tolerance 값입니다.</td></tr><tr><td>Boolean</td><td>State Clustering 적용 여부입니다.</td></tr></tbody></table>

#### 반환

<table><thead><tr><th width="155">Type</th><th width="395">Description</th><th>Default</th></tr></thead><tbody><tr><td>List&#x3C;State></td><td>필터링 후 탐색 대상이  State 리스트 입니다.</td><td><a href="#default-logic-11">Default Logic 참조</a> </td></tr></tbody></table>

#### 예제 (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)
```

#### 정의

Local 필터링 로직을 정의하고 이를 통해 탐색할 State 리스트를 반환합니다.

#### 매개 변수

| Type         | Description                   |
| ------------ | ----------------------------- |
| List\<State> | 필터링 하기 전 State 리스트 입니다.       |
| Integer      | 필터링 후 탐색을 진행할 최대 State 수 입니다. |

#### 반환

<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>필터링 후 탐색 대상이  State 리스트 입니다.</td><td><a href="#default-logic-12">Default Logic 참조</a></td></tr></tbody></table>

#### 예제 (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)
```

#### 정의

근사 로직을 통해 탐색할 State의 수를 줄일 때 주어진 State가 탐색 대상에서 제외될 지 여부를 설정합니다.

#### 매개 변수

<table><thead><tr><th width="238">Type</th><th width="510">Description</th></tr></thead><tbody><tr><td>State</td><td>판단 대상 State 입니다.</td></tr><tr><td>ObjectiveFunctionType</td><td>문제의 목적함수 타입입니다. (Maximize, Minimize)</td></tr><tr><td>Double</td><td>탐색 후보 State들의 가치함수 근사치 중 가장 작은 값입니다.</td></tr><tr><td>Double</td><td>발생 가능한 가장 작은 Transition cost 입니다.</td></tr><tr><td>Double</td><td>Multiplier 파라메터 값 입니다.</td></tr><tr><td>Double</td><td>State Prune 조건 판단 시 적용되는 Tolerance 값입니다.</td></tr></tbody></table>

#### 반환

<table><thead><tr><th width="129">Type</th><th width="392">Description</th><th>Default</th></tr></thead><tbody><tr><td>Boolean</td><td>대상 State Prune 여부입니다.</td><td><a href="#default-logic-13">Default Logic 참조</a></td></tr></tbody></table>

#### 예제 (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;
    }
}
```
