All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.gitlab.chaver.mining.patterns.util.PatternCreator Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
/*
 * This file is part of io.gitlab.chaver:data-mining (https://gitlab.com/chaver/data-mining)
 *
 * Copyright (c) 2022, IMT Atlantique
 *
 * Licensed under the MIT license.
 *
 * See LICENSE file in the project root for full license information.
 */
package io.gitlab.chaver.mining.patterns.util;

import io.gitlab.chaver.chocotools.util.Creator;
import io.gitlab.chaver.mining.patterns.io.Database;
import io.gitlab.chaver.mining.patterns.io.Pattern;
import lombok.AllArgsConstructor;
import org.chocosolver.solver.variables.BoolVar;
import org.chocosolver.solver.variables.IntVar;

import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;

@AllArgsConstructor
public class PatternCreator implements Creator {

    private Database database;
    private BoolVar[] items;
    private List allMeasuresId;
    private Map measureVars;
    private TransactionGetter transactionGetter;

    @Override
    public Pattern create() {
        int[] itemSave = IntStream
                .range(0, items.length)
                .filter(i -> items[i].isInstantiatedTo(1))
                .map(i -> database.getItems()[i])
                .toArray();
        int[] measureSave = new int[allMeasuresId.size()];
        for (int i = 0; i < allMeasuresId.size(); i++) {
            measureSave[i] = measureVars.get(allMeasuresId.get(i)).getValue();
        }
        Pattern p = new Pattern(itemSave, measureSave);
        if (transactionGetter != null) p.setTransactions(transactionGetter.getTransactions());
        return p;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy