Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added some ways to run the algorithms more easily.

  • Loading branch information...
commit f777f4ee58bbb04e4df7b36b9aedacdac67dda0f 1 parent ca15b00
@kokx authored
View
17 Main.java
@@ -8,11 +8,11 @@
Scanner sc;
Algorithm algo;
- public Main()
+ public Main(Algorithm algo)
{
sc = new Scanner(System.in);
- algo = new Optics();
+ this.algo = algo;
}
/**
@@ -89,9 +89,16 @@ void run(boolean reachability)
public static void main(String args[])
{
boolean reach = false;
- if (args.length >= 1 && "reach".equals(args[0])) {
- reach = true;
+ Algorithm algo = new Optics();
+
+ for (String arg : args) {
+ if ("reach".equals(arg)) {
+ reach = true;
+ } else if ("noise".equals(arg) || "allnoise".equals(arg)) {
+ algo = new Allnoise();
+ }
}
- new Main().run(reach);
+
+ new Main(algo).run(reach);
}
}
View
41 algorithm/Allnoise.java
@@ -0,0 +1,41 @@
+package algorithm;
+
+import java.io.*;
+import java.util.*;
+import java.lang.reflect.Array;
+
+import model.*;
+import algorithm.*;
+
+/**
+ * Stub algorithm.
+ */
+public class Allnoise extends Algorithm
+{
+ /**
+ * Constructor.
+ */
+ public Allnoise()
+ {
+ super();
+ }
+
+ /**
+ * Find the parameters
+ *
+ * @param ci Minimum number of clusters
+ * @param cj Maximum number of clusters
+ * @param n Number of points
+ */
+ public void findParameters(int ci, int cj, int n, long width, long height)
+ {
+ super.findParameters(ci, cj, n, width, height);
+ }
+
+ public void run()
+ {
+ for (Point p : field.getAllPoints()) {
+ p.setCluster(0);
+ }
+ }
+}
View
18 cluster
@@ -11,6 +11,7 @@
# -q Quality measure
# -t Time algorithm (cannot be used in combination with -R)
# -nv Run visualization, but do not display the image
+# -no Do not run a real algorithm.
# functions
@@ -27,19 +28,22 @@ compile() {
run()
{
- export reach=""
+ export params=""
if [ $1 ]; then
if [ $1 = "-r" ]; then
- export reach="reach"
+ export params="reach"
message "Reachability plot....."
else
message "Running..............."
+ if [ $1 = "allnoise" ]; then
+ export params="allnoise"
+ fi
fi
else
message "Running..............."
fi
- java Main $reach
+ java Main $params
}
run_file()
@@ -64,6 +68,7 @@ export R=""
export q=""
export t=""
export nv=""
+export params=""
for arg in $@
do
@@ -83,6 +88,9 @@ do
-nv)
export nv="t"
;;
+ -no)
+ export params="allnoise"
+ ;;
*)
file=$arg
;;
@@ -101,9 +109,9 @@ if [ "$R" = "t" ]; then
else
# run and visualize
if [ "$t" = "t" ]; then
- time_run_file $file | tee $file.out | java visualize.Main
+ time_run_file $file $params | tee $file.out | java visualize.Main
else
- run_file $file | tee $file.out | java visualize.Main
+ run_file $file $params | tee $file.out | java visualize.Main
fi
if [ "$nv" = "t" ]; then
less $file.out
View
4 generate
@@ -2,11 +2,11 @@
# first compile all files
-./compile
+./cluster
java generator.Main > input/$1
-cat input/$1 | java Main > input/$1.out
+cat input/$1 | java Main allnoise > input/$1.out
# visualization
View
34 generator/Main.java
@@ -8,11 +8,12 @@
class Main {
Scanner sc;
- public final static int CLUSTERS = 6;
- public final static int CLUSTER_MIN_SIZE = 100;
- public final static int CLUSTER_MAX_SIZE = 500;
+ public final static int CLUSTERS = 5;
+ public final static int CLUSTER_MIN_SIZE = 300;
+ public final static int CLUSTER_MAX_SIZE = 600;
public final static int CLUSTER_MIN_DENSITY = 5000;
public final static int CLUSTER_MAX_DENSITY = 25000;
+ public final static int FIELD_SIZE = 10000;
public Main()
{
@@ -21,20 +22,33 @@ public Main()
void run()
{
+ int field = FIELD_SIZE;
Generator generator = new Generator(5000, 5000);
- generator.createUniformNoise(300);
+ generator.createUniformNoise(100);
+ generator.generateGaussianNoise(10, 600, 300);
+ field -= 300;
+ field -= 1800;
Random random = generator.getRandomGenerator();
- for (int i = 0; i < CLUSTERS; i++) {
- int size = CLUSTER_MIN_SIZE + random.nextInt(CLUSTER_MAX_SIZE - CLUSTER_MIN_SIZE);
- int density = CLUSTER_MIN_DENSITY + random.nextInt(CLUSTER_MAX_DENSITY - CLUSTER_MIN_DENSITY);
+ // create an array with cluster sizes
+ int clusters[] = new int [CLUSTERS];
+ int points = 0;
- generator.generateCluster(size, density);
+ for (int i = 0; i < CLUSTERS; i++) {
+ clusters[i] = CLUSTER_MIN_SIZE + random.nextInt(CLUSTER_MAX_SIZE - CLUSTER_MIN_SIZE);
+ points += clusters[i];
}
- generator.generateGaussianNoise(10, 600, 1800);
+ // density, number of points per square in the grid
+ double density = field / ((double) points);
+
+ //System.out.println("Dens: " + density + " Field: " + field + " Points: " + points);
+
+ for (int i = 0; i < CLUSTERS; i++) {
+ generator.generateCluster(clusters[i], (int) (density * clusters[i]));
+ }
output(generator.getField());
}
@@ -43,7 +57,7 @@ void output(Field field)
{
Collection<Point> points = field.getAllPoints();
- System.out.println("find 2 to 4 clusters");
+ System.out.println("find " + CLUSTERS + " clusters");
System.out.println(field.size() + " points");
for (Point p : points) {
Please sign in to comment.
Something went wrong with that request. Please try again.