package com.aps.macroplanner.variable;

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

/**
 * 生产变量构建器 — 创建 PTQty 变量。
 *
 * <p>PTQty[operationId_unitId_periodIndex] — 生产量变量</p>
 * <ul>
 *   <li>索引: Operation × UnitOperation × Period</li>
 *   <li>含义: 某个操作在某个单元、某个周期内的生产数量</li>
 *   <li>范围: [0, +∞)</li>
 * </ul>
 */
public class ProductionVariableBuilder {

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