public override State GetInitialState()
초기 State를 정의합니다.
public override State GetInitialState()
{
CRPData data = DataManager.Instance.Data as CRPData;
CRPState initState = new CRPState();
initState.SetStateInfo(data.CRPFactory.Conveyors);
return initState;
}
public override string GetKey(State state)
State의 Key를 정의합니다.
public virtual string GetKey(State state)
{
return state.Index.ToString();
}
public override Solution GetFeasibleSolution(State state)
주어진 State를 기준으로 Feasible solution을 구하는 로직을 정의합니다.
public override Solution GetFeasibleSolution(State state)
{
CRPState crpState = state as CRPState;
CRPState copiedState = crpState.Clone();
copiedState.IsInitial = false;
List<CRPState> states = new List<CRPState>();
states.AddRange(copiedState.GetBestStatesBackward().Cast<CRPState>().ToList());
while (copiedState.JobCount > 0)
{
Stage stage = new Stage(copiedState.Stage.Index + 1);
copiedState.Stage = stage;
CRPJob lastJob = copiedState.LastRetrievedJob;
CRPConveyor sameColorConv = copiedState.GetSameColorConveyor(lastJob);
CRPJob retrievedJob = null;
if (sameColorConv != null)
{
retrievedJob = copiedState.RetrieveJob(sameColorConv.ConveyorNum);
}
else
{
retrievedJob = copiedState.RetrieveJob();
}
double cost = 0;
if (lastJob != null && lastJob.Color.ColorNumber != retrievedJob.Color.ColorNumber)
cost = 1;
copiedState.BestValue += cost;
states.Add(copiedState);
copiedState = copiedState.Clone();
}
Solution feasibleSol = new Solution(states);
return feasibleSol;
}
public override bool CanPruneByOptimality(State state, ObjectiveFunctionType objFuncType, double pruneTolerance)
주어진 State가 최적성을 잃지 않고 Prune 될 수 있는지 여부를 판단합니다. 만약, 해당 State가 Prune 조건을 만족한다면 탐색 대상에서 제외됩니다.
public override bool CanPruneByOptimality(State state, ObjectiveFunctionType objFuncType, double pruneTolerance)
{
BoundManager boundManager = BoundManager.Instance;
double bestPrimalBound = boundManager.BestPrimalBound;
double dualBound = state.DualBound;
double bestValue = state.BestValue;
double rootDualBound = boundManager.RootDualBound;
if (objFuncType == ObjectiveFunctionType.Minimize)
{
if (dualBound < rootDualBound - bestValue)
dualBound = rootDualBound - bestValue;
if (bestPrimalBound + pruneTolerance <= bestValue + dualBound)
return true;
else
return false;
}
else
{
if (dualBound > rootDualBound - bestValue)
dualBound = rootDualBound - bestValue;
if (bestPrimalBound >= bestValue + dualBound + pruneTolerance)
return true;
else
return false;
}
}