我需要分析PlanningEntity的结果以计算两次生产订单分配之间的时间

时间:2019-04-24 14:05:36

标签: optaplanner

我正在开发食品行业生产订单排序系统。

更改设备中生产的产品时,我需要分析两个生产订单之间的设备设置时间。

我正在尝试使用阴影变量,但是我需要分析optaplanner的求解器的结果。为此,我使用的是从afterEntityAdded方法的ScoreDirector获得的分配列表(PlanningEntity)。

此程序正确吗?

“阴影变量代码”

private static final Logger logger = LoggerFactory.getLogger(SetupVariableListener.class);

@Override
public void beforeEntityAdded(ScoreDirector scoreDirector, Alocacao entity) {
    // Do nothing
}

@Override
public void afterEntityAdded(ScoreDirector scoreDirector, Alocacao entity) {
    updateAllocation(scoreDirector, entity);
}

@Override
public void beforeVariableChanged(ScoreDirector scoreDirector, Alocacao entity) {
    // Do nothing
}

@Override
public void afterVariableChanged(ScoreDirector scoreDirector, Alocacao entity) {
    updateAllocation(scoreDirector, entity);
}

@Override
public void beforeEntityRemoved(ScoreDirector scoreDirector, Alocacao entity) {
    // Do nothing
}

@Override
public void afterEntityRemoved(ScoreDirector scoreDirector, Alocacao entity) {
    // Do nothing
}

protected void updateAllocation(ScoreDirector scoreDirector, Alocacao originalAllocation) {
    boolean updated = false;
    int tempo = 0;
    int tempoPausa = 0;
    Hashtable<Setup, Integer> st = new Hashtable<>();
    Agenda agenda = (Agenda) scoreDirector.getWorkingSolution();
    if (originalAllocation.getProcessoProducao().getSequenciaProducao() == 1) {
        List<Alocacao> alocacoes = agenda.getAlocacoesOrdens().stream().filter(g -> g.getProcessoProducao().getSequenciaProducao() == 1 && g.getEquipamento().equals(originalAllocation.getEquipamento())).sorted((a1, b1) -> {
            return new CompareToBuilder()
                    .append(a1.getProcessoProducao().getOrdemProducao().getNrOrdemProducao(), b1.getProcessoProducao().getOrdemProducao().getNrOrdemProducao())
                    .append(a1.getProcessoProducao().getOrdemProducao().getSequenciaDivisao(), b1.getProcessoProducao().getOrdemProducao().getSequenciaDivisao())
                    .append(a1.getProcessoProducao().getSequenciaProducao(), b1.getProcessoProducao().getSequenciaProducao())
                    .toComparison();
        }).collect(Collectors.toList());
        int posicaoOrigem = alocacoes.indexOf(originalAllocation);
        if ((posicaoOrigem + 1) < alocacoes.size()) {
            SeqItem itemOrigem = originalAllocation.getProcessoProducao().getOrdemProducao().getItem();
            SeqItem itemDestino = alocacoes.get(posicaoOrigem + 1).getProcessoProducao().getOrdemProducao().getItem();
            Setup s = new Setup(itemOrigem, itemDestino, 0);
            tempo = agenda.getListaSetup().get(s);
            st.put(s, tempo);

            SeqPeriodo seqOrigem = originalAllocation.getPeriodoInicial();
            SeqPeriodo seqDestino = alocacoes.get(posicaoOrigem + 1).getPeriodoInicial();
            if (seqOrigem != null && seqDestino != null) {
                tempoPausa = seqDestino.getPeriodoIndex() - seqOrigem.getPeriodoIndex();
            }

            //tempo = agenda.getListaSetup().stream().filter(g -> g.getItemOrigem().equals(s.getItemOrigem())).filter(g -> g.getItemDestino().equals(s.getItemDestino())).collect(Collectors.toList()).get(0).getTempo();
        }
    }
    originalAllocation.setTempoSetup(tempo);
    originalAllocation.setDiferencaProximaProducao(tempoPausa);
    originalAllocation.setSetupSelecionado(st);

}

0 个答案:

没有答案