package com.aps.macroplanner.variable;

import com.google.ortools.linearsolver.MPSolver;
import com.aps.macroplanner.data.*;
import com.aps.macroplanner.model.MacroPlannerModel;

/**
 * 批次松弛变量构建器 — 创建 PTLotSizeOver 和 PTLotSizeUnder 变量。
 *
 * <p>仅在操作定义了批次大小时创建。</p>
 *
 * <h3>PTLotSizeOver[operationId_unitId_periodIndex]</h3>
 * <ul><li>含义: 生产量超出批次大小的量</li><li>范围: [0, +∞)</li></ul>
 *
 * <h3>PTLotSizeUnder[operationId_unitId_periodIndex]</h3>
 * <ul><li>含义: 生产量不足批次大小的量</li><li>范围: [0, +∞)</li></ul>
 */
public class LotSizeVariableBuilder {

    public static void create(MacroPlannerModel model, TestDataBuilder data) {
        double inf = MPSolver.infinity();
        for (Operation op : data.getOperations()) {
            for (UnitOperation uo : op.getUnitOperations()) {
                if (!uo.hasLotSize()) continue;
                for (Period p : data.getPeriods()) {
                    String key = op.ptQtyKey(uo, p.getIndex());
                    model.getPtLotSizeOverVars().put(key,
                            model.getSolver().makeNumVar(0.0, inf, "LotOver_" + key));
                    model.getPtLotSizeUnderVars().put(key,
                            model.getSolver().makeNumVar(0.0, inf, "LotUnder_" + key));
                }
            }
        }
    }
}