Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
aad041a
Complement and comment functional interfaces
Sep 3, 2020
8d9dcc7
Implement new functional interfaces to deal with primitive types
Sep 18, 2020
815652f
Implement interface PrimitiveIterable
Sep 22, 2020
4298a08
Implement functional iteration API similar to Streams
Sep 18, 2020
37f1bec
Adapt IntSet to properly implement IterableInt
Sep 4, 2020
e11e25a
Implement class Range to supersede Interval and RangeIntIterable
Sep 4, 2020
10e5923
Adjust classpath to include test directory
Sep 15, 2020
83ae25b
Implement assertions on iterators
Sep 21, 2020
ea60ab7
Test interface Reducible
merkste Aug 27, 2021
823f613
Test interface PrimitiveReducible
merkste Aug 27, 2021
777b86a
Test interface FunctionalIterator
merkste Aug 27, 2021
60dfe57
Test interface FunctionalPrimitiveIterator
merkste Aug 27, 2021
6f9ad37
Test interface FunctionalIterable
merkste Aug 27, 2021
67c0b14
Test interface FunctionalPrimitiveIterable
merkste Aug 27, 2021
c1811af
Test IteratorAdaptor
merkste Aug 27, 2021
9e9e5d8
Test IterableAdaptor
merkste Aug 27, 2021
af2a4ba
Test ArrayIterator
merkste Aug 27, 2021
fe75e40
Test IterableArray
merkste Aug 27, 2021
faa075e
Test EmptyIterator
merkste Aug 27, 2021
ecad67a
Test EmptyIterable
merkste Aug 27, 2021
69c674a
Test SingletonIterator
merkste Aug 27, 2021
0cd74ee
Test SingletonIterable
merkste Aug 27, 2021
b7a275b
Test PrimitiveIterable
merkste Aug 27, 2021
7271711
Test ChainedIterator
merkste Aug 27, 2021
ce15205
Test ChainedIterable
merkste Aug 27, 2021
448d8fb
Test MappingIterator
merkste Aug 27, 2021
955f2a9
Test MappingIterable
merkste Aug 27, 2021
70dfec0
Test Distinct
merkste Aug 27, 2021
bc30369
Test FilteringIterator
merkste Aug 27, 2021
a234749
Test FilteringIterable
merkste Aug 27, 2021
610bb12
Test Range
merkste Aug 27, 2021
2ee47b1
Add JUnit platform to libs
merkste Aug 31, 2021
51cf24f
Add Makefile to build tests
merkste Aug 31, 2021
1bde980
Run unit tests from Makefile
merkste Aug 31, 2021
279e213
Improve initial states generation
Aug 9, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion prism/.classpath
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="unit-tests"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/epsgraphics.jar"/>
<classpathentry kind="lib" path="lib/jcommon.jar"/>
<classpathentry kind="lib" path="lib/jfreechart.jar" sourcepath="/jfreechart/source"/>
Expand All @@ -12,5 +17,6 @@
<classpathentry kind="lib" path="lib/jas.jar"/>
<classpathentry kind="lib" path="lib/log4j.jar"/>
<classpathentry kind="lib" path="lib/nailgun-server.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="classes"/>
</classpath>
23 changes: 22 additions & 1 deletion prism/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# If this is a problem, the best solution is to create symlinks.

export PRISM_SRC_DIR = src
export PRISM_TESTS_DIR = unit-tests
export PRISM_CLASSES_DIR = classes
export PRISM_OBJ_DIR = obj
export PRISM_LIB_DIR = lib
Expand Down Expand Up @@ -176,6 +177,7 @@ else
endif
LD = $(CXX)
JAVAC = javac
JAVA = java

export CC CXX LD JAVAC JAVACC

Expand Down Expand Up @@ -323,6 +325,7 @@ export CFLAGS CXXFLAGS LDFLAGS JFLAGS LIBPREFIX LIBSUFFIX
##########################################

MAKE_DIRS = dd jdd odd dv prism mtbdd sparse hybrid parser settings userinterface pepa/compiler simulator jltl2ba jltl2dstar explicit pta param strat automata common cex
TEST_DIRS = common

EXT_PACKAGES = lpsolve55 lp_solve_5.5_java

Expand Down Expand Up @@ -368,7 +371,7 @@ extpackages: checks

# Compile main PRISM code
# (we also do some preparatory checks, and build launch scripts afterwards)
prism: checks make_dirs bin_scripts
prism: checks make_dirs bin_scripts make_tests

# Compile each (top-level) source directory separately
make_dirs:
Expand Down Expand Up @@ -397,6 +400,22 @@ make_dirs:
(dos2unix $(PRISM_INCLUDE_DIR)/jni/*.h) \
fi;

make_tests:
@for dir in $(TEST_DIRS); do \
echo Making $(PRISM_TESTS_DIR)/$$dir ...; \
(cd $(PRISM_TESTS_DIR)/$$dir && \
$(MAKE) \
CUDD_DIR="$(CUDD_DIR)" \
JAVA_INCLUDES="$(JAVA_INCLUDES)" \
JAVA_JNI_H_DIR="$(JAVA_JNI_H_DIR)" \
JAVA_JNI_MD_H_DIR="$(JAVA_JNI_MD_H_DIR)" \
SHARED="$(SHARED)" \
EXE="$(EXE)" \
LIBMATH="$(LIBMATH)" \
CLASSPATHSEP="$(CLASSPATHSEP)") \
|| exit 1; \
done; \

# Copy/modify the launch scripts and put in the bin directory
bin_scripts:
@for target in $(BIN_TARGETS); do \
Expand Down Expand Up @@ -472,6 +491,8 @@ count_loc:
###########
# Testing #
###########
unittests:
$(JAVA) -jar lib/junit-platform-console-standalone-1.7.2.jar -cp classes --scan-classpath

# Run a single test case from the test suite (useful quick check that the build was ok)
test:
Expand Down
Binary file not shown.
124 changes: 53 additions & 71 deletions prism/src/common/IntSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Copyright (c) 2016-
// Authors:
// * Joachim Klein <klein@tcs.inf.tu-dresden.de> (TU Dresden)
// * Steffen Maercker <steffen.maercker@tu-dresden.de> (TU Dresden)
//
//------------------------------------------------------------------------------
//
Expand All @@ -27,13 +28,18 @@
package common;

import java.util.BitSet;
import java.util.Objects;
import java.util.PrimitiveIterator;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.PrimitiveIterator.OfInt;
import java.util.function.IntPredicate;
import java.util.stream.IntStream;
import java.util.stream.StreamSupport;

import common.IterableBitSet;
import common.iterable.FunctionalPrimitiveIterable;
import common.iterable.FunctionalPrimitiveIterator;
import common.iterable.SingletonIterable;

/**
* Interface for an ordered set of integers that allows efficient
Expand All @@ -42,27 +48,24 @@
* <br>
* Provides static helpers for wrapping a BitSet or a singleton value.
*/
public interface IntSet extends Iterable<Integer>
public interface IntSet extends FunctionalPrimitiveIterable.OfInt
{
/** Return a PrimitiveIterator.OfInt iterator for iteration, normal order */
public OfInt iterator();

/** Return a PrimitiveIterator.OfInt iterator for iteration, reversed order */
public OfInt reversedIterator();
/** Return a FunctionalPrimitiveIterator.OfInt iterator for iteration, reversed order */
FunctionalPrimitiveIterator.OfInt reversedIterator();

/** Return the cardinality (number of elements) for this set */
public int cardinality();

/** Return true if {@code index} is a member of this set */
public boolean contains(int index);
default long cardinality()
{
return count();
}

/**
* Return true if {@code index} is a member of this set
* (convenience method to ease migration from use of BitSet).
* <p>
* <i>Default implementation</i>: Calls contains(index).
*/
public default boolean get(int index)
default boolean get(int index)
{
return contains(index);
}
Expand All @@ -74,9 +77,9 @@ public default boolean get(int index)
* <i>Default implementation</i>:
* Tests via contains for all elements of other.
*/
public default boolean contains(IntSet other)
default boolean contains(IntSet other)
{
return other.stream().allMatch(this::contains);
return other.allMatch((IntPredicate) this::contains);
}

/**
Expand All @@ -86,7 +89,7 @@ public default boolean contains(IntSet other)
* <i>Default implementation</i>:
* Uses contains(IntSet other).
*/
public default boolean contains(BitSet other)
default boolean contains(BitSet other)
{
return contains(asIntSet(other));
}
Expand All @@ -97,23 +100,32 @@ public default boolean contains(BitSet other)
* <i>Default implementation</i>:
* Wrap iterator() into an intStream.
*/
public default IntStream stream() {
default IntStream stream()
{
return StreamSupport.intStream(
() -> Spliterators.spliterator(
iterator(), cardinality(),
Spliterator.DISTINCT),
() -> spliterator(),
Spliterator.SIZED | Spliterator.DISTINCT,
false);
}

@Override
default Spliterator.OfInt spliterator()
{
return Spliterators.spliterator(
iterator(),
cardinality(),
Spliterator.SIZED | Spliterator.DISTINCT);
}

/** Return this set as a String */
public default String asString()
@Override
default String asString()
{
// can't overload toString() with a default method in interface
StringBuffer sb = new StringBuffer();
sb.append("{");
boolean first = true;
for (OfInt it = iterator(); it.hasNext(); ) {
for (PrimitiveIterator.OfInt it = iterator(); it.hasNext(); ) {
if (!first)
sb.append(",");
first = false;
Expand All @@ -123,33 +135,36 @@ public default String asString()
return sb.toString();
}



/**
* Wrapper class for obtaining an IntSet from a BitSet.
* <p>
* Note: The BitSet should not be modified as long as the
* derived IntSet is in use.
*/
public static class IntSetFromBitSet implements IntSet
static class IntSetFromBitSet implements IntSet
{
/** The wrapped BitSet */
private BitSet bs;
protected BitSet bs;
/** The cardinality of the underlying BitSet (cached, -1 = not yet computed) */
int cardinality = -1;

/** Constructor */
public IntSetFromBitSet(BitSet bs)
{
Objects.requireNonNull(bs);
this.bs = bs;
}

@Override
public OfInt iterator()
public FunctionalPrimitiveIterator.OfInt iterator()
{
return IterableBitSet.getSetBits(bs).iterator();
}

@Override
public OfInt reversedIterator()
public FunctionalPrimitiveIterator.OfInt reversedIterator()
{
return IterableBitSet.getSetBitsReversed(bs).iterator();
}
Expand All @@ -161,7 +176,7 @@ public IntStream stream()
}

@Override
public int cardinality()
public long count()
{
// not yet computed?
if (cardinality == -1)
Expand All @@ -183,86 +198,53 @@ public String toString()
}
};



/** Convenience class for simulating a singleton set */
public static class SingletonIntSet implements IntSet
static class SingletonIntSet extends SingletonIterable.OfInt implements IntSet
{
/** The single member of this singleton set */
private int singleMember;

/**
* Constructor.
* @param singleMember the single member of this set
*/
public SingletonIntSet(int singleMember)
{
this.singleMember = singleMember;
super(singleMember);
}

@Override
public OfInt iterator()
{
return new OfInt() {
boolean done = false;
@Override
public boolean hasNext()
{
return !done;
}
@Override
public int nextInt()
{
done = true;
return singleMember;
}
};
}

@Override
public OfInt reversedIterator()
public FunctionalPrimitiveIterator.OfInt reversedIterator()
{
// iteration order does not matter for singleton set
return iterator();
}

@Override
public int cardinality()
{
return 1;
}

@Override
public boolean contains(int index)
{
return index == singleMember;
}

@Override
public String toString()
{
return "{" + singleMember + "}";
return "{" + element + "}";
}

}

/**
* Static constructor for obtaining an IntSet from a BitSet
* Factory method for obtaining an IntSet from a BitSet
* <p>
* Note: The BitSet should not be modified as long as the derived IntSet is in use.
*
* @param bs The underlying BitSet
*/
public static IntSet asIntSet(BitSet bs)
static IntSet asIntSet(BitSet bs)
{
return new IntSetFromBitSet(bs);
}

/**
* Static constructor for obtaining an IntSet for a singleton set.
* Factory method for obtaining an IntSet for a singleton set.
*
* @param singleMember The single member of the singleton set
*/
public static IntSet asIntSet(int singleMember)
static IntSet asIntSet(int singleMember)
{
return new SingletonIntSet(singleMember);
}

}

Loading