Permalink
Browse files

Fixed running errors.

  • Loading branch information...
1 parent 6a825f5 commit 58a767bb95e2f534b734187ff1d1f708bd227b27 @kokx committed May 8, 2012
View
@@ -1,6 +1,8 @@
import java.io.*;
import java.util.*;
+import model.*;
+
class Main {
Scanner sc;
View
@@ -3,6 +3,8 @@
import java.io.*;
import java.util.*;
+import model.*;
+
public abstract class Algorithm
{
@@ -21,7 +23,7 @@ public Algorithm(Field field)
/**
* Run the algorithm.
*/
- public abstract void run()
+ public abstract void run();
/**
* Determine the distance between sourcePoint and destPoint.
@@ -31,17 +33,16 @@ public abstract void run()
* @param m 2 = Euclidean, 1 = Manhatten
* @return Distance from sourcePoint to destPoint
*/
- public int Distance(Point sourcePoint, Point destPoint, int m) {
+ public double Distance(Point sourcePoint, Point destPoint, int m)
+ {
+ long dx = (long) Math.abs(destPoint.getX() - sourcePoint.getX());
+ long dy = (long) Math.abs(destPoint.getY() - sourcePoint.getY());
+
switch (m) {
case 1:
- return Math.abs(destPoint.getX() - sourcePoint.getX())
- + Math.abs(destPoint.getY() - sourcePoint.getY());
- break;
- case 2:
- return Math.sqrt(Math.pow(Math.abs(destPoint.getX() - sourcePoint.getX()), 2)
- + Math.pow(Math.abs(destPoint.getY() - sourcePoint.getY()), 2));
- break;
+ return (double) (dx + dy);
+ default:
+ return Math.pow(Math.pow(dx, m) + Math.pow(dy, m), 1.0/m);
}
}
-
}
View
@@ -3,10 +3,22 @@
import java.io.*;
import java.util.*;
+import model.*;
+
public class DeLiClu extends Algorithm
{
- void run()
+ /**
+ * Constructor.
+ *
+ * @param field
+ */
+ public DeLiClu(Field field)
+ {
+ super(field);
+ }
+
+ public void run()
{
// magic
}
View
@@ -3,6 +3,8 @@
import java.io.*;
import java.util.*;
+import model.*;
+
class Generator {
public final static int DEFAULT_MAX_OFFSET = 100000;
View
@@ -3,6 +3,8 @@
import java.io.*;
import java.util.*;
+import model.*;
+
class Main {
Scanner sc;
View
@@ -47,7 +47,7 @@ public Point getCentroid() {
long totalx = 0;
long totaly = 0;
- for (Point point : pointList) {
+ for (Point point : points) {
totalx += point.getX();
totaly += point.getY();
}
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -6,6 +6,8 @@
import java.awt.*;
import javax.imageio.*;
+import model.*;
+
class Main {
Scanner sc;
View
@@ -2,6 +2,8 @@
import java.util.ArrayList;
+import model.*;
+
public class Quality {
private ArrayList<Cluster> clusterList;
@@ -14,10 +16,10 @@ private Point calcCentroid(Cluster cluster) {
int size = cluster.size();
long totalx = 0;
long totaly = 0;
- int centroidx, centroidy;
+ int centroidx = 0, centroidy = 0;
ArrayList<Point> pointList;
- pointList = cluster.getPointsList();
- for (Point point : pointList) {
+ ArrayList<Point> points = cluster.getPoints();
+ for (Point point : points) {
totalx += point.getX();
totaly += point.getY();
}
View
12 run
@@ -1,15 +1,13 @@
#!/bin/sh
-javac Main.java
+
+# first compile all files
+
+javac Main.java algorithm/*.java generator/*.java model/*.java quality/*.java visualize/*.java
cat $1 | java Main > $1.out
# visualization
-cd visualize/
-javac Main.java
-
-cat ../$1.out | java Main
+cat $1.out | java visualize.Main
xdg-open output.png
-
-cd ..
View
@@ -6,6 +6,8 @@
import java.awt.*;
import javax.imageio.*;
+import model.*;
+
class Main {
Scanner sc;
BufferedImage img;

0 comments on commit 58a767b

Please sign in to comment.