Quintiq file version 2.0
|
#parent: #root
|
Method InitVariablesForCampaignCombiSelection (
|
CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
|
const RunContextForCapacityPlanning runcontext,
|
const LibOpt_Scope scope
|
) const
|
{
|
Description: 'init variables method for campaign sequencing optimizer'
|
TextBody:
|
[*
|
if( runcontext.UseCampaignSequenceOptimizer() and runcontext.UseCampaign() )
|
{
|
operationsinscope := scope.GetOperationInOptimizerRunConst();
|
computenvar := this.MacroPlan().Optimization().DebugMode();
|
|
program.RegisterTypeDescriptor( attribute( OptCampaignUnitSubPeriod, Name ) );
|
program.RegisterTypeDescriptor( attribute( OptCampaignCombi, Name ) );
|
program.RegisterTypeDescriptor( attribute( OptCampaignCombiElement, Name ) );
|
program.RegisterTypeDescriptor( attribute( OptCampaignElementType, Name ) );
|
program.RegisterTypeDescriptor( attribute( OptCampaignUnit, UnitID ) );
|
program.RegisterTypeDescriptor( attribute( OptCampaignOperationInElementType, Name ) );
|
|
traverse( scope.GetUnitPeriodInOptimizerRunConst(), Elements.OptCampaignUnitSubPeriod, ocusp )
|
{
|
assert( forall( ocusp, OptCampaignCombiSelected, combiselected, combiselected.IsActive() ), 'failed assertion: selected combi is not active ' );
|
program.UnderSelectionOfCampaignCombiVariables().New( ocusp )
|
program.IsIncompatibleWithPrevOptSubUnitPeriodLastElementVariables().New( ocusp )
|
|
traverse( ocusp, OptCampaignCombiActive, combi )
|
{
|
var := program.IsCampaignCombiSelectedVariables().New( combi );
|
var.StartValue( ifexpr( combi.IsSelectedByOptimizer(), 1.0, 0.0 ) );
|
if ( combi.DebugIsFixedPlanned() )
|
{
|
valueplanned := ifexpr( combi.IsSelectedByOptimizer(), 1.0, 0.0 );
|
var.UpperBound( valueplanned );
|
var.LowerBound( valueplanned );
|
}
|
}
|
traverse( ocusp, OptCampaignCombiElement.OptCampaignElementType, ocet )
|
{
|
//If this is a transition, we want these constraints to be hard ones
|
if( not ocet.istype( OptCampaignTransitionType ) )
|
{
|
program.MinCampaignElementTypeQtyUnderWithinVariables().New( ocet, ocusp );
|
program.MinCampaignElementTypeQtyUnderMultiVariables().New( ocet, ocusp );
|
|
program.MinCampaignElementTypeDurUnderWithinVariables().New( ocet, ocusp );
|
program.MinCampaignElementTypeDurUnderMultiVariables().New( ocet, ocusp );
|
|
program.MaxCampaignElementTypeQtyOverWithinVariables().New( ocet, ocusp );
|
if ( isnull( ocusp.NextSubPeriod() ) )
|
{
|
program.MaxCampaignElementTypeQtyOverWithinLastVariables().New( ocet, ocusp );
|
}
|
program.MaxCampaignElementTypeQtyOverMultiPeriodVariables().New( ocet, ocusp );
|
|
program.MaxCampaignElementTypeDurOverWithinVariables().New( ocet, ocusp );
|
program.MaxCampaignElementTypeDurOverMultiVariables().New( ocet, ocusp );
|
}
|
|
program.CampaignElementTypePeriodOverloadedStartVariables().New( ocet, ocusp );
|
program.CampaignElementTypePeriodOverloadedMidVariables().New( ocet, ocusp );
|
program.CampaignElementTypePeriodOverloadedEndVariables().New( ocet, ocusp );
|
|
program.CampaignElementTypePeriodUnderloadedStartVariables().New( ocet, ocusp );
|
program.CampaignElementTypePeriodUnderloadedMidVariables().New( ocet, ocusp );
|
program.CampaignElementTypePeriodUnderloadedEndVariables().New( ocet, ocusp );
|
|
program.DurationOfCampaignElementTypeMidVariables().New( ocet, ocusp );
|
program.DurationOfCampaignElementTypeEndVariables().New( ocet, ocusp );
|
program.DurationOfCampaignElementTypeStartVariables().New( ocet, ocusp );
|
|
program.NrOfCampaignElementWithinUnitSubPeriodVariables().New( ocet, ocusp )
|
|
program.IsFirstCampaignElementTypeVariables().New( ocet, ocusp )
|
program.IsLastCampaignElementTypeVariables().New( ocet, ocusp )
|
|
program.IsMultiPeriodsFirstCampaignElementTypeFirstPeriodVariables().New( ocet, ocusp )
|
|
traverse( ocet, OptCampaignOperationInElementType, ocoet )
|
{
|
varstart := program.PTQtyInCampaignElementTypeStartVariables().New( ocoet, ocusp );
|
varmid := program.PTQtyInCampaignElementTypeMidVariables().New( ocoet, ocusp );
|
varend := program.PTQtyInCampaignElementTypeEndVariables().New( ocoet, ocusp );
|
|
if( operationsinscope.Find( ocoet.Operation() ) < 0 )
|
{
|
varstart.UpperBound( 0.0 );
|
varmid.UpperBound( 0.0 );
|
varend.UpperBound( 0.0 );
|
}
|
}
|
}
|
}
|
|
// fixing debug values
|
traverse( scope.GetUnitPeriodInOptimizerRunConst(), Elements.OptCampaignUnitSubPeriod, ocusp )
|
{
|
traverse( ocusp, OptCampaignCombiActive, combi )
|
{
|
traverse( combi, OptCampaignCombiElement, occelt )
|
{
|
ocet := occelt.OptCampaignElementType();
|
subperiod := occelt.OptCampaignUnitSubPeriod();
|
midvar := program.DurationOfCampaignElementTypeMidVariables().Get( ocet, subperiod );
|
endvar := program.DurationOfCampaignElementTypeEndVariables().Get( ocet, subperiod );
|
startvar := program.DurationOfCampaignElementTypeStartVariables().Get( ocet, subperiod );
|
|
// note that these variables are shared among combi elements with the same type and sub period.
|
// in the handle feasible we write back duplicated to the combi element objects
|
// here we only set for the combi that has been fixed - which for normal debugging it would mean we only set
|
// values ones because there will be at most 1 combi per unit period
|
|
if ( occelt.DebugFixStartDuration() )
|
{
|
startvar.LowerBound( occelt.DebugDurationOfCampaignElementTypeStartVariables() );
|
startvar.UpperBound( startvar.LowerBound() );
|
|
if ( startvar.UpperBound() = 0.0 )
|
{
|
traverse( ocet, OptCampaignOperationInElementType, ocoet )
|
{
|
program.PTQtyInCampaignElementTypeStartVariables().Get( ocoet, subperiod ).UpperBound ( 0.0 );
|
}
|
}
|
}
|
if ( occelt.DebugFixMidDuration() )
|
{
|
midvar.LowerBound( occelt.DebugDurationOfCampaignElementTypeMidVariables() );
|
midvar.UpperBound( midvar.LowerBound() );
|
|
if ( midvar.UpperBound() = 0.0 )
|
{
|
traverse( ocet, OptCampaignOperationInElementType, ocoet )
|
{
|
program.PTQtyInCampaignElementTypeMidVariables().Get( ocoet, subperiod ).UpperBound ( 0.0 );
|
}
|
}
|
}
|
if ( occelt.DebugFixEndDuration() )
|
{
|
endvar.LowerBound( occelt.DebugDurationOfCampaignElementTypeEndVariables() );
|
endvar.UpperBound( endvar.LowerBound() );
|
|
if ( endvar.UpperBound() = 0.0 )
|
{
|
traverse( ocet, OptCampaignOperationInElementType, ocoet )
|
{
|
program.PTQtyInCampaignElementTypeEndVariables().Get( ocoet, subperiod ).UpperBound ( 0.0 );
|
}
|
}
|
}
|
}
|
}
|
}
|
|
// Creating Goal variables
|
program.TotalUnitPeriodCampaignUtilizationSlackVariables().New();
|
program.TotalCampaignSequencingCombiSlackVariables().New();
|
program.TotalCampaignMinQtyUnderVariables().New();
|
program.TotalCampaignMaxQtyOverVariables().New();
|
program.TotalCampaignMinDurationUnderVariables().New();
|
program.TotalCampaignMaxDurationOverVariables().New();
|
|
if( computenvar )
|
{
|
periods := counter( scope.GetUnitPeriodInOptimizerRunConst(), Elements.OptCampaignUnitSubPeriod, ocusp, true );
|
debuginfo( " -Number of campaign subunitperiods: ", periods );
|
combis := sum( scope.GetUnitPeriodInOptimizerRunConst(), Elements.OptCampaignUnitSubPeriod, ocusp, true, counter( ocusp, OptCampaignCombiActive, combi, true ) );
|
debuginfo( " -Number of campaign combis ", combis )
|
}
|
}
|
*]
|
}
|