001/*
002 * @author Francesco.Kriegel@gmx.de
003 */
004package conexp.fx.core.collections.relation;
005
006/*
007 * #%L
008 * Concept Explorer FX
009 * %%
010 * Copyright (C) 2010 - 2023 Francesco Kriegel
011 * %%
012 * This program is free software: you can redistribute it and/or modify
013 * it under the terms of the GNU General Public License as
014 * published by the Free Software Foundation, either version 3 of the
015 * License, or (at your option) any later version.
016 * 
017 * This program is distributed in the hope that it will be useful,
018 * but WITHOUT ANY WARRANTY; without even the implied warranty of
019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
020 * GNU General Public License for more details.
021 * 
022 * You should have received a copy of the GNU General Public
023 * License along with this program.  If not, see
024 * <http://www.gnu.org/licenses/gpl-3.0.html>.
025 * #L%
026 */
027
028import java.util.Collection;
029import java.util.Set;
030
031import com.google.common.base.Predicate;
032
033import conexp.fx.core.collections.Pair;
034import conexp.fx.core.collections.setlist.SetList;
035import conexp.fx.core.math.PartialComparable;
036
037public interface Relation<R, C> extends Iterable<Pair<R, C>>, PartialComparable<Relation<R, C>>, Cloneable {
038
039  public SetList<R> rowHeads();
040
041  public SetList<C> colHeads();
042
043  public boolean add(R row, C col);
044
045  public boolean addFast(Object o1, Object o2);
046
047  public boolean addAll(Relation<? extends R, ? extends C> r);
048
049  public boolean addAllFast(Relation<?, ?> r);
050
051  public boolean contains(Object o1, Object o2);
052
053  public boolean containsAll(Relation<?, ?> r);
054
055  public boolean remove(Object o1, Object o2);
056
057  public boolean removeAll(Relation<?, ?> r);
058
059  public boolean retainAll(Relation<?, ?> r);
060
061  public Set<C> row(Object o);
062
063  public Set<R> col(Object o);
064
065  public Set<C> rowAnd(Object... o);
066
067  public Set<R> colAnd(Object... o);
068
069  public Set<C> rowAnd(Collection<?> c);
070
071  public Set<R> colAnd(Collection<?> c);
072
073  public Relation<R, C> subRelation(Collection<?> rowHeads, Collection<?> colHeads);
074
075  public Relation<R, C> filter(
076      Predicate<? super R> rowPredicate,
077      Predicate<? super C> colPredicate,
078      Predicate<Pair<R, C>> relationPredicate);
079
080  public int size();
081
082  default public double density() {
083    return ((double) size()) / ((double) (rowHeads().size() * colHeads().size()));
084  }
085
086  public boolean isEmpty();
087
088  public boolean isFull();
089
090  public void empty();
091
092  public void fill();
093
094  public void dispose();
095
096  public MatrixRelation<R, C> clone();
097
098  public boolean[][] toArray();
099
100  public static final class NoHomogenRelationException extends RuntimeException {
101
102    private static final long serialVersionUID = -3920949710978936537L;
103
104    public NoHomogenRelationException() {
105      super();
106    }
107  }
108
109  public boolean isHomogen();
110
111  public MatrixRelation<R, R> neighborhood() throws NoHomogenRelationException;
112
113  public MatrixRelation<R, R> order() throws NoHomogenRelationException;
114
115  public SetList<Set<R>> equivalenceClasses() throws NoHomogenRelationException;
116}