io.gitlab.chaver.mining.patterns.util.PatternCreator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of data-mining Show documentation
Show all versions of data-mining Show documentation
Data mining with Choco solver
/*
* 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;
}
}