Commit be09a04e authored by Charles Vernerey's avatar Charles Vernerey
Browse files

Add AdequateClosure test

parent bf571481
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
/*
 * 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.constraints;

import io.gitlab.chaver.mining.patterns.io.Database;
import io.gitlab.chaver.mining.patterns.measure.Measure;
import org.chocosolver.solver.variables.BoolVar;

import java.util.List;

public class AdequateClosureDCTest extends AdequateClosureTest {

    @Override
    protected AdequateClosure getAdequateClosure(Database database, List<Measure> measures, BoolVar[] x) {
        return new AdequateClosureDC(database, measures, x);
    }
}
+53 −0
Original line number Diff line number Diff line
/*
 * 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.constraints;

import io.gitlab.chaver.mining.patterns.io.DatReader;
import io.gitlab.chaver.mining.patterns.io.Database;
import io.gitlab.chaver.mining.patterns.measure.Measure;
import org.chocosolver.solver.Model;
import org.chocosolver.solver.Solution;
import org.chocosolver.solver.constraints.Constraint;
import org.chocosolver.solver.variables.BoolVar;
import org.chocosolver.solver.variables.IntVar;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import static io.gitlab.chaver.mining.patterns.measure.MeasureFactory.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

public abstract class AdequateClosureTest {

    private final String resPath = "src/test/resources/";

    protected abstract AdequateClosure getAdequateClosure(Database database, List<Measure> measures, BoolVar[] x);

    private void testFindClosedPatterns(String dataPath, int nbExpectedClosed, List<Measure> measures, int nbValMeasures)
            throws IOException {
        Model model = new Model("closed test");
        Database database = new DatReader(dataPath, nbValMeasures, true).readFiles();
        IntVar freq = model.intVar("freq", 1, database.getNbTransactions());
        IntVar length = model.intVar("length", 1, database.getNbItems());
        BoolVar[] x = model.boolVarArray("x", database.getNbItems());
        model.sum(x, "=", length).post();
        model.post(new Constraint("Cover Size", new CoverSize(database, freq, x)));
        model.post(new Constraint("Closed", getAdequateClosure(database, measures, x)));
        List<Solution> sols = model.getSolver().findAllSolutions();
        assertEquals(nbExpectedClosed, sols.size());
    }

    @Test
    public void testFindClosedSdm() throws IOException {
        testFindClosedPatterns(resPath + "sdm/sdm.dat", 17, Arrays.asList(freq(), min(0)), 1);
    }
}
+24 −0
Original line number Diff line number Diff line
/*
 * 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.constraints;

import io.gitlab.chaver.mining.patterns.io.Database;
import io.gitlab.chaver.mining.patterns.measure.Measure;
import org.chocosolver.solver.variables.BoolVar;

import java.util.List;

public class AdequateClosureWCTest extends AdequateClosureTest {

    @Override
    protected AdequateClosure getAdequateClosure(Database database, List<Measure> measures, BoolVar[] x) {
        return new AdequateClosureWC(database, measures, x);
    }
}
+7 −0
Original line number Diff line number Diff line
2 5 6
2 3 4
1 5 6
1 2 3 4 5
2 3 4 5
2 3 4 5 6
1 2 3 4 5 6
 No newline at end of file
+6 −0
Original line number Diff line number Diff line
0.30
0.40
0.10
0.40
0.70
0.50
 No newline at end of file