structures.MedianConstraints.java Source code

Java tutorial

Introduction

Here is the source code for structures.MedianConstraints.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package structures;

import com.google.common.collect.Sets;
import java.util.Set;
import structures.concurrent.AtomicSet;

/**
 *
 * @author ntak
 */
public abstract class MedianConstraints {

    protected int size;
    protected int nb_constraints; // the number of constraints knowned.
    protected Set[][] e;

    public abstract void addConstraint(int i, int j, boolean update_exclusion_set, boolean verbose)
            throws Exception;

    public abstract boolean isConstraintValid(int i, int j);

    public abstract boolean isPairSolve(int i, int j);

    public abstract Set[][] buildExclusionSetTable();

    public abstract boolean isSolve();

    /**
     * Getters
     */
    public abstract Set getExclusionSet(int i, int j);

    public abstract int getNb_constraints();

    public abstract int getSize();

    public abstract Set<Integer> getBeforeSet(int i);

    public abstract Set<Integer> getAfterSet(int i);

    public double getPercentageFound() {
        return nb_constraints * 100 / (new Double(size * (size - 1)) / 2);
    };

    @Override
    public abstract boolean equals(Object o);

    public abstract MedianConstraints copy();

    public Set[][] copyExclusionSets() {

        if (this.e != null) {
            Set[][] copy = new Set[size][size];
            for (int i = 0; i < this.size; i++) {
                for (int j = i; j < this.size; j++) {
                    if (this.e[i][j] != null) {
                        copy[i][j] = Sets.newTreeSet(this.e[i][j]);
                    }
                }
            }
            return copy;
        }
        return null;
    }
}