package com.aps.macroplanner.variable;

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

/**
 * 产能松弛变量构建器 — 创建 CapacityOverloaded 和 CapacityNotMet 变量。
 *
 * <h3>CapacityOverloaded[unitId_periodIndex]</h3>
 * <ul>
 *   <li>含义: 设备产能超出最大限制的量</li>
 *   <li>范围: [0, +∞)</li>
 * </ul>
 *
 * <h3>CapacityNotMet[unitId_periodIndex]</h3>
 * <ul>
 *   <li>含义: 设备产能低于最小使用的量</li>
 *   <li>范围: [0, +∞)</li>
 * </ul>
 */
public class CapacityVariableBuilder {

    public static void create(MacroPlannerModel model, TestDataBuilder data) {
        double inf = MPSolver.infinity();
        for (UnitPeriod up : data.getUnitPeriods()) {
            if (up.isUnlimited()) continue; // 无限产能无需松弛变量
            String key = up.getKey();
            model.getCapacityOverloadedVars().put(key,
                    model.getSolver().makeNumVar(0.0, inf, "CapOver_" + key));
            model.getCapacityNotMetVars().put(key,
                    model.getSolver().makeNumVar(0.0, inf, "CapNotMet_" + key));
        }
    }
}