add power bench.
authoryeom <yeom>
Thu, 25 Mar 2010 23:15:35 +0000 (23:15 +0000)
committeryeom <yeom>
Thu, 25 Mar 2010 23:15:35 +0000 (23:15 +0000)
15 files changed:
Robust/src/Benchmarks/mlp/power/#makefile# [new file with mode: 0644]
Robust/src/Benchmarks/mlp/power/Branch.java [new file with mode: 0644]
Robust/src/Benchmarks/mlp/power/Demand.java [new file with mode: 0644]
Robust/src/Benchmarks/mlp/power/Lateral.java [new file with mode: 0644]
Robust/src/Benchmarks/mlp/power/Leaf.java [new file with mode: 0644]
Robust/src/Benchmarks/mlp/power/Power.java [new file with mode: 0644]
Robust/src/Benchmarks/mlp/power/Root.java [new file with mode: 0644]
Robust/src/Benchmarks/mlp/power/makefile [new file with mode: 0644]
Robust/src/Tests/disjoint/power_new/Branch.java [new file with mode: 0644]
Robust/src/Tests/disjoint/power_new/Demand.java [new file with mode: 0644]
Robust/src/Tests/disjoint/power_new/Lateral.java [new file with mode: 0644]
Robust/src/Tests/disjoint/power_new/Leaf.java [new file with mode: 0644]
Robust/src/Tests/disjoint/power_new/Power.java [new file with mode: 0644]
Robust/src/Tests/disjoint/power_new/Root.java [new file with mode: 0644]
Robust/src/Tests/disjoint/power_new/makefile [new file with mode: 0644]

diff --git a/Robust/src/Benchmarks/mlp/power/#makefile# b/Robust/src/Benchmarks/mlp/power/#makefile#
new file mode 100644 (file)
index 0000000..334c10a
--- /dev/null
@@ -0,0 +1,30 @@
+#raytracer
+PROGRAM=test
+
+SOURCE_FILES=Power.java
+
+BUILDSCRIPT=~/eclipse/workspaces/irvine_sep09/Robust/src/buildscript
+
+USEMLP=  -mlp 8 2  -mlpdebug  # use to turn mlp on and off and make sure rest of build not broken
+BSFLAGS=   -32bit -optimize -mainclass Power -debug -garbagestats 
+OWNERSHIP= -ownership -ownallocdepth 1 -enable-assertions  -methodeffects -flatirusermethods -ownwritedots final -ownaliasfile aliases.txt 
+
+default:
+       ../../../buildscript -nojava $(USEMLP) $(BSFLAGS) $(OWNERSHIP) -o $(PROGRAM)p $(SOURCE_FILES) -builddir par
+
+single:
+       ../../../buildscript $(BSFLAGS) -o $(PROGRAM)s $(SOURCE_FILES) -builddir sing
+
+java:
+       ../../../buildscript $(USEMLP) $(BSFLAGS) $(OWNERSHIP) -o $(PROGRAM)p $(SOURCE_FILES) -builddir par
+
+clean:
+       rm -f  $(PROGRAM).bin
+       rm -fr par sing
+       rm -f  *~
+       rm -f  *.dot
+       rm -f  *.png
+       rm -f  *.txt
+       rm -f  aliases.txt
+       rm -f  mlpReport*txt
+       rm -f  results*txt
diff --git a/Robust/src/Benchmarks/mlp/power/Branch.java b/Robust/src/Benchmarks/mlp/power/Branch.java
new file mode 100644 (file)
index 0000000..fcabf06
--- /dev/null
@@ -0,0 +1,108 @@
+/**
+ * A class that represents a branch node in the power pricing architecture. A
+ * branch node is another type of intermediate node that represents a split in
+ * the electrical power path. The branch nodes hang from the lateral nodes. <b>
+ * Each branch node contains a direct link to a set of customers.
+ **/
+final class Branch {
+       /**
+        * Demand for the customers supported by the branch node.
+        **/
+       Demand D;
+       double alpha;
+       double beta;
+       double R;
+       double X;
+       /**
+        * A link to the next branch node that has the same parent (lateral) node.
+        **/
+       Branch nextBranch;
+       /**
+        * A list of customers - represented a leaf nodes.
+        **/
+       Leaf[] leaves;
+
+       /**
+        * Create all the branch nodes for a single lateral node. Also, create the
+        * customers supported by this branch node
+        * 
+        * @param num
+        *            a counter to limit the branch nodes created for the lateral
+        *            node
+        * @param nleaves
+        *            the nubmer of leafs to create per branch
+        **/
+       public Branch(int num, int nleaves) {
+
+               alpha = 0.0;
+               beta = 0.0;
+               R = 0.0001;
+               X = 0.00002;
+
+               D = new Demand(0.0, 0.0);
+
+               if (num <= 1) {
+                       if (num <= 0)
+//                             throw new RuntimeException("Branch constructor with zero num");
+                               System.out.println("Branch constructor with zero num");
+                       nextBranch = null;
+               } else {
+                       nextBranch = new Branch(num - 1, nleaves);
+               }
+
+               // fill in children
+               leaves = new Leaf[nleaves];
+               for (int k = 0; k < nleaves; k++) {
+                       leaves[k] = new Leaf();
+               }
+       }
+
+       /**
+        * Pass the prices down and compute the demand for the power system.
+        * 
+        * @param theta_R
+        *            real power multiplier
+        * @param theta_I
+        *            reactive power multiplier
+        * @param pi_R
+        *            the real power price
+        * @param pi_I
+        *            the reactive power price
+        * @return the demand for the customers supported by this branch
+        **/
+       public Demand compute(double theta_R, double theta_I, double pi_R,
+                       double pi_I) {
+               double new_pi_R = pi_R + alpha * (theta_R + (theta_I * X) / R);
+               double new_pi_I = pi_I + beta * (theta_I + (theta_R * R) / X);
+
+               Demand a1 = null;
+               if (nextBranch != null) {
+                       a1 = nextBranch.compute(theta_R, theta_I, new_pi_R, new_pi_I);
+               }
+
+               // Initialize and pass the prices down the tree
+               D.reset();
+               for (int i = 0; i < leaves.length; i++) {
+                       D.increment(leaves[i].compute(new_pi_R, new_pi_I));
+               }
+               if (nextBranch != null) {
+                       D.increment(a1);
+               }
+
+               // pass demand up, P, Q
+               double a = R * R + X * X;
+               double b = 2 * R * X * D.Q - 2 * X * X * D.P - R;
+               double c = R * D.Q - X * D.P;
+               c = c * c + R * D.P;
+               double root = (-b - Math.sqrt(b * b - 4 * a * c)) / (2 * a);
+               D.Q = D.Q + ((root - D.P) * X) / R;
+               D.P = root;
+               // compute alpha, beta
+               a = 2 * R * D.P;
+               b = 2 * X * D.Q;
+               alpha = a / (1 - a - b);
+               beta = b / (1 - a - b);
+
+               return D;
+       }
+}
diff --git a/Robust/src/Benchmarks/mlp/power/Demand.java b/Robust/src/Benchmarks/mlp/power/Demand.java
new file mode 100644 (file)
index 0000000..f6b369d
--- /dev/null
@@ -0,0 +1,241 @@
+/**
+ * A class that represents power demand.
+ **/
+final class Demand {
+       /**
+        * Real power demand.
+        **/
+       public double P;
+       /**
+        * Reactive power demand.
+        **/
+       public double Q;
+
+       private static double F_EPSILON;
+       private static double G_EPSILON;
+       private static double H_EPSILON;
+
+       /**
+        * Create an object that represents power demand and initialize the power
+        * demans values.
+        * 
+        * @param toP
+        *            the real power demand
+        * @param toQ
+        *            the reactive power demand
+        **/
+       Demand(double toP, double toQ) {
+               F_EPSILON = 0.000001;
+               G_EPSILON = 0.000001;
+               H_EPSILON = 0.000001;
+
+               P = toP;
+               Q = toQ;
+       }
+
+       /**
+        * Create an empry power demand object.
+        **/
+//     Demand() {
+//             this(0.0, 0.0);
+//     }
+
+       /**
+        * Increment the demand.
+        * 
+        * @param frm
+        *            the amount to increase the demand
+        **/
+       void increment(Demand frm) {
+               P += frm.P;
+               Q += frm.Q;
+       }
+
+       /**
+        * Reset the power demand values.
+        **/
+       void reset() {
+               P = 0.0;
+               Q = 0.0;
+       }
+
+       /**
+        * Add the demand values from the two inputs.
+        * 
+        * @param a1
+        *            the demand values for operand1
+        * @param a2
+        *            the demand values for operand2
+        **/
+       void add(Demand a1, Demand a2) {
+               P = a1.P + a2.P;
+               Q = a1.Q + a2.Q;
+       }
+
+       /**
+        * Assign the demand from the specified value to this one.
+        * 
+        * @param frm
+        *            the demand assigned to this object.
+        **/
+       void assign(Demand frm) {
+               P = frm.P;
+               Q = frm.Q;
+       }
+
+       /**
+        * Calculate the power demand given the prices. The pricing problem sets the
+        * price for each customer's power consumption so that the economic
+        * efficiency of the whole community is maximied.
+        * 
+        * @param pi_R
+        *            price for real power
+        * @param pi_I
+        *            price for reactive power
+        **/
+       void optimizeNode(double pi_R, double pi_I) {
+               double[] grad_f = new double[2];
+               double[] grad_g = new double[2];
+               double[] grad_h = new double[2];
+               double[] dd_grad_f = new double[2];
+
+               double g, h;
+               do {
+                       // Move onto h=0 line
+                       h = findH();
+                       if (Math.abs(h) > H_EPSILON) {
+                               double magnitude = findGradientH(grad_h);
+                               double total = h / magnitude;
+                               P -= total * grad_h[0];
+                               Q -= total * grad_h[1];
+                       }
+
+                       // Check that g is still valid
+                       g = findG();
+                       if (g > G_EPSILON) {
+                               double magnitude = findGradientG(grad_g);
+                               findGradientH(grad_h);
+                               magnitude *= makeOrthogonal(grad_g, grad_h);
+                               double total = g / magnitude;
+                               P -= total * grad_g[0];
+                               Q -= total * grad_g[1];
+                       }
+
+                       // Maximize benefit
+                       double magnitude = findGradientF(pi_R, pi_I, grad_f);
+                       findDDGradF(pi_R, pi_I, dd_grad_f);
+                       double total = 0.0;
+                       for (int i = 0; i < 2; i++)
+                               total += grad_f[i] * dd_grad_f[i];
+                       magnitude /= Math.abs(total);
+                       findGradientH(grad_h);
+                       magnitude *= makeOrthogonal(grad_f, grad_h);
+                       findGradientG(grad_g);
+                       total = 0.0;
+                       for (int i = 0; i < 2; i++)
+                               total += grad_f[i] * grad_g[i];
+                       if (total > 0) {
+                               double max_dist = -findG() / total;
+                               if (magnitude > max_dist)
+                                       magnitude = max_dist;
+                       }
+                       P += magnitude * grad_f[0];
+                       Q += magnitude * grad_f[1];
+
+                       h = findH();
+                       g = findG();
+                       findGradientF(pi_R, pi_I, grad_f);
+                       findGradientH(grad_h);
+               } while (Math.abs(h) > H_EPSILON
+                               || g > G_EPSILON
+                               || (Math.abs(g) > G_EPSILON && Math.abs(grad_f[0] * grad_h[1]
+                                               - grad_f[1] * grad_h[0]) > F_EPSILON));
+       }
+
+       private double findG() {
+               return (P * P + Q * Q - 0.8);
+       }
+
+       private double findH() {
+               return (P - 5 * Q);
+       }
+
+       private double findGradientF(double pi_R, double pi_I, double[] gradient) {
+               gradient[0] = 1 / (1 + P) - pi_R;
+               gradient[1] = 1 / (1 + Q) - pi_I;
+
+               double magnitude = 0.0;
+               for (int i = 0; i < 2; i++)
+                       magnitude += gradient[i] * gradient[i];
+
+               magnitude = Math.sqrt(magnitude);
+
+               for (int i = 0; i < 2; i++)
+                       gradient[i] /= magnitude;
+
+               return magnitude;
+       }
+
+       private double findGradientG(double[] gradient) {
+               gradient[0] = 2 * P;
+               gradient[1] = 2 * Q;
+               double magnitude = 0.0;
+               for (int i = 0; i < 2; i++)
+                       magnitude += gradient[i] * gradient[i];
+
+               magnitude = Math.sqrt(magnitude);
+
+               for (int i = 0; i < 2; i++)
+                       gradient[i] /= magnitude;
+
+               return magnitude;
+       }
+
+       private double findGradientH(double[] gradient) {
+               gradient[0] = 1.0;
+               gradient[1] = -5.0;
+               double magnitude = 0.0;
+               for (int i = 0; i < 2; i++)
+                       magnitude += gradient[i] * gradient[i];
+               magnitude = Math.sqrt(magnitude);
+               for (int i = 0; i < 2; i++)
+                       gradient[i] /= magnitude;
+
+               return magnitude;
+       }
+
+       private void findDDGradF(double pi_R, double pi_I, double[] dd_grad) {
+               double P_plus_1_inv = 1 / (P + 1);
+               double Q_plus_1_inv = 1 / (Q + 1);
+               double P_grad_term = P_plus_1_inv - pi_R;
+               double Q_grad_term = Q_plus_1_inv - pi_I;
+
+               double grad_mag = Math.sqrt(P_grad_term * P_grad_term + Q_grad_term
+                               * Q_grad_term);
+
+               dd_grad[0] = -P_plus_1_inv * P_plus_1_inv * P_grad_term / grad_mag;
+               dd_grad[1] = -Q_plus_1_inv * Q_plus_1_inv * Q_grad_term / grad_mag;
+       }
+
+       private double makeOrthogonal(double[] v_mod, double[] v_static) {
+               double total = 0.0;
+               for (int i = 0; i < 2; i++)
+                       total += v_mod[i] * v_static[i];
+
+               double length = 0.0;
+               for (int i = 0; i < 2; i++) {
+                       v_mod[i] -= total * v_static[i];
+                       length += v_mod[i] * v_mod[i];
+               }
+               length = Math.sqrt(length);
+
+               for (int i = 0; i < 2; i++)
+                       v_mod[i] /= length;
+
+               if (1 - total * total < 0) // Roundoff error
+                       return 0;
+
+               return Math.sqrt(1 - total * total);
+       }
+
+}
diff --git a/Robust/src/Benchmarks/mlp/power/Lateral.java b/Robust/src/Benchmarks/mlp/power/Lateral.java
new file mode 100644 (file)
index 0000000..460602a
--- /dev/null
@@ -0,0 +1,108 @@
+/**
+ * A class that represents a lateral node in the power pricing problem. The
+ * lateral nodes is an intermediate node that represents a switch, tappoints, or
+ * transformer. It hangs from the root node (the power substation).
+ * <p>
+ * Each lateral node is the head in a line of branch nodes.
+ **/
+final class Lateral {
+       /**
+        * Demand for the customers supported by the lateral node.
+        **/
+       Demand D;
+       double alpha;
+       double beta;
+       double R;
+       double X;
+       /**
+        * The next lateral that shares the same parent (root) node.
+        **/
+       Lateral next_lateral;
+       /**
+        * The branch nodes that are supported by the lateral node.
+        **/
+       Branch branch;
+
+       /**
+        * Create all the lateral nodes for a single root node.
+        * 
+        * @param num
+        *            the child number of the lateral wrt the root
+        * @param nbranches
+        *            the number of branch nodes per lateral.
+        * @param nleaves
+        *            the number of leaf nodes per branch.
+        **/
+       Lateral(int num, int nbranches, int nleaves) {
+
+               alpha = 0.0;
+               beta = 0.0;
+               R = 1 / 300000.0;
+               X = 0.000001;
+
+               D = new Demand(0.0,0.0);
+
+               // create a linked list of the lateral nodes
+               if (num <= 1) {
+                       if (num <= 0)
+//                             throw new RuntimeException("Lateral constructor with zero num");
+                               System.out.println("Lateral constructor with zero num");
+                       next_lateral = null;
+               } else {
+                       next_lateral = new Lateral(num - 1, nbranches, nleaves);
+               }
+
+               // create the branch nodes
+               branch = new Branch(nbranches, nleaves);
+       }
+
+       /**
+        * Pass prices down and compute demand for the power system.
+        * 
+        * @param theta_R
+        *            real power demand multiplier
+        * @param theta_I
+        *            reactive power demand multiplier
+        * @param pi_R
+        *            price of real power demand
+        * @param pi_I
+        *            price of reactive power demand
+        * @return the demand for the customers supported by this lateral
+        **/
+       Demand compute(double theta_R, double theta_I, double pi_R, double pi_I) {
+               // generate the new prices and pass them down to the customers
+               double new_pi_R = pi_R + alpha * (theta_R + (theta_I * X) / R);
+               double new_pi_I = pi_I + beta * (theta_I + (theta_R * R) / X);
+
+               Demand a1;
+               if (next_lateral != null)
+                       a1 = next_lateral.compute(theta_R, theta_I, new_pi_R, new_pi_I);
+               else
+                       a1 = null;
+
+               Demand a2 = branch.compute(theta_R, theta_I, new_pi_R, new_pi_I);
+
+               if (next_lateral != null) {
+                       D.add(a1, a2);
+               } else {
+                       D.assign(a2);
+               }
+
+               // compute the new power demand values P,Q
+               double a = R * R + X * X;
+               double b = 2 * R * X * D.Q - 2 * X * X * D.P - R;
+               double c = R * D.Q - X * D.P;
+               c = c * c + R * D.P;
+               double root = (-b - Math.sqrt(b * b - 4 * a * c)) / (2 * a);
+               D.Q = D.Q + ((root - D.P) * X) / R;
+               D.P = root;
+
+               // compute alpha, beta
+               a = 2 * R * D.P;
+               b = 2 * X * D.Q;
+               alpha = a / (1 - a - b);
+               beta = b / (1 - a - b);
+               
+               return D;
+       }
+}
diff --git a/Robust/src/Benchmarks/mlp/power/Leaf.java b/Robust/src/Benchmarks/mlp/power/Leaf.java
new file mode 100644 (file)
index 0000000..5867a57
--- /dev/null
@@ -0,0 +1,38 @@
+/**
+ * A class that represents a customer in the power system optimization problem.
+ * A customer is a leaf node in tree representation of the problem.
+ **/
+final class Leaf {
+       /**
+        * Power demand for the customer
+        **/
+       Demand D;
+       /**
+        * Price for real power demand
+        **/
+       double pi_R;
+       /**
+        * Price for reaactive power demand
+        **/
+       double pi_I;
+
+       Leaf() {
+               D = new Demand(1.0, 1.0);
+       }
+
+       /**
+        * Pass prices down and compute demand for the customer.
+        * 
+        * @return the power demand for the customer
+        **/
+       Demand compute(double pi_R, double pi_I) {
+               D.optimizeNode(pi_R, pi_I);
+
+               if (D.P < 0.0) {
+                       D.P = 0.0;
+                       D.Q = 0.0;
+               }
+               return D;
+       }
+
+}
diff --git a/Robust/src/Benchmarks/mlp/power/Power.java b/Robust/src/Benchmarks/mlp/power/Power.java
new file mode 100644 (file)
index 0000000..cae2902
--- /dev/null
@@ -0,0 +1,100 @@
+/**
+ * A Java implementation of the <tt>power</tt> Olden benchmark. The original
+ * algorithm is from the following paper:
+ * <p>
+ * <cite> S. Lumetta, L. Murphy, X. Li, D. Culler, and I. Khalil. "Decentralized
+ * optimal power pricing: The development of a parallel program." Supercomputing
+ * '93, 243-249 </cite>
+ * <p>
+ * Note - the number of customers is fixed at 10,000 for this benchmark. We
+ * create a data structure that contains 1 root (the (power substation). There
+ * are 10 main feeders from the root and each feeder branches to 20 lateral
+ * nodes. Each lateral node is the head of a line of five branch nodes and each
+ * branch has 10 customers. In total, there are 10,000 customers (and 1201
+ * internal nodes).
+ * <p>
+ * The power pricing problems sets the price of each customer's power
+ * consumption so that the economic efficiency of the whole community is
+ * maximized.
+ **/
+public class Power {
+       /**
+        * Should we print the results as we run the benchmark
+        **/
+//     static boolean printResults;
+       /**
+        * Print information messages?
+        **/
+//     static boolean printMsgs;
+
+       /**
+        * The main routine which creates the power network and runs the simulation
+        * 
+        * @param args
+        *            the command line args
+        **/
+       public static void main(String args[]) {
+
+               boolean printResults = true;
+               boolean printMsgs =true;
+               // the input size is fixed, but the user may want the result printed
+               // parseCmdLine(args);
+
+               // initial pass
+               long start0 = System.currentTimeMillis();
+               Root r = new Root(10, 20, 5, 10);
+               long end0 = System.currentTimeMillis();
+
+               long start1 = System.currentTimeMillis();
+               r.compute();
+               r.nextIter(false, 0.7, 0.14);
+
+               while (true) {
+                       r.compute();
+                       if (printResults)
+                               System.out.println(r);
+
+                       if (r.reachedLimit())
+                               break;
+
+                       r.nextIter(printResults);
+               } /* while */
+
+               long end1 = System.currentTimeMillis();
+
+               if (printMsgs) {
+                       System.out.println("Power build time " + (end0 - start0) / 1000.0);
+                       System.out
+                                       .println("Power compute time " + (end1 - start1) / 1000.0);
+                       System.out.println("Power total time " + (end1 - start0) / 1000.0);
+               }
+               System.out.println("Done!");
+       }
+
+       /**
+        * Parse the command line options.
+        * 
+        * @param args
+        *            the command line options.
+        **/
+       /*
+        * private static final void parseCmdLine(String args[]) { int i = 0; String
+        * arg;
+        * 
+        * while (i < args.length && args[i].startsWith("-")) { arg = args[i++]; if
+        * (arg.equals("-h")) { usage(); } else if (arg.equals("-p")) { printResults
+        * = true; } else if (arg.equals("-m")) { printMsgs = true; } } }
+        */
+
+       /**
+        * The usage routine which describes the program options.
+        **/
+       private static final void usage() {
+               System.out.println("usage: java Power [-p] [-m] [-h]");
+               System.out.println("    -p (print results)");
+               System.out.println("    -m (print informative messages)");
+               System.out.println("    -h (this message)");
+               System.exit(0);
+       }
+
+}
diff --git a/Robust/src/Benchmarks/mlp/power/Root.java b/Robust/src/Benchmarks/mlp/power/Root.java
new file mode 100644 (file)
index 0000000..3663a6f
--- /dev/null
@@ -0,0 +1,314 @@
+import com.enea.jcarder.transactionalinterfaces.HashMap;
+
+import dstm2.AtomicSuperClass;
+
+/**
+ * The root node of the power system optimization tree. The root node represents
+ * the power plant.
+ **/
+final class Root {
+       /**
+        * Total system power demand.
+        **/
+       Demand D;
+       
+       double P,Q;
+       /**
+        * Lagrange multiplier for the global real power equality constraint
+        **/
+       double theta_R;
+       /**
+        * Lagrange multiplier for the global reactive power equality constraint
+        **/
+       double theta_I;
+       /**
+        * The power demand on the previous iteration
+        **/
+       Demand last;
+       /**
+        * The real power equality constraint on the previous iteration
+        **/
+       double last_theta_R;
+       /**
+        * The reactive power equality constraint on the previous iteration
+        **/
+       double last_theta_I;
+       /**
+        * A representation of the customers that feed off of the power plant.
+        **/
+       Lateral[] feeders;
+
+       /**
+        * Value used to compute convergence
+        **/
+       private static double ROOT_EPSILON;
+
+       /**
+        * Domain of thetaR->P map is 0.65 to 1.00 [index*0.01+0.65]
+        **/
+       private static double map_P[];
+
+       private static double MIN_THETA_R;
+       private static double PER_INDEX_R;
+       private static double MAX_THETA_R;
+
+       /**
+        * Domain of thetaI->Q map is 0.130 to 0.200 [index*0.002+0.130]
+        **/
+       private static double map_Q[];
+
+       private static double MIN_THETA_I;
+       private static double PER_INDEX_I;
+       private static double MAX_THETA_I;
+       
+       /**
+        * Create the tree used by the power system optimization benchmark. Each
+        * root contains <tt>nfeeders</tt> feeders which each contain
+        * <tt>nlaterals</tt> lateral nodes, which each contain <tt>nbranches</tt>
+        * branch nodes, which each contain <tt>nleafs</tt> leaf nodes.
+        * 
+        * @param nfeeders
+        *            the number of feeders off of the root
+        * @param nlaterals
+        *            the number of lateral nodes per feeder
+        * @param nbranches
+        *            the number of branches per lateral
+        * @param nleaves
+        *            the number of leaves per branch
+        **/
+       Root(int nfeeders, int nlaterals, int nbranches, int nleaves) {
+
+               theta_R = 0.8;
+               theta_I = 0.16;
+               ROOT_EPSILON = 0.00001;
+               map_P = new double[36];
+
+               map_P[0] = 8752.218091048;
+               map_P[1] = 8446.106670416;
+               map_P[2] = 8107.990680283;
+               map_P[3] = 7776.191574285;
+               map_P[4] = 7455.920518777;
+               map_P[5] = 7146.602181352;
+               map_P[6] = 6847.709026813;
+               map_P[7] = 6558.734204024;
+               map_P[8] = 6279.213382291;
+               map_P[9] = 6008.702199986;
+               map_P[10] = 5746.786181029;
+               map_P[11] = 5493.078256495;
+               map_P[12] = 5247.206333097;
+               map_P[13] = 5008.828069358;
+               map_P[14] = 4777.615815166;
+               map_P[15] = 4553.258735900;
+               map_P[16] = 4335.470002316;
+               map_P[17] = 4123.971545694;
+               map_P[18] = 3918.501939675;
+               map_P[19] = 3718.817618538;
+               map_P[20] = 3524.683625800;
+               map_P[21] = 3335.876573044;
+               map_P[22] = 3152.188635673;
+               map_P[23] = 2973.421417103;
+               map_P[24] = 2799.382330486;
+               map_P[25] = 2629.892542617;
+               map_P[26] = 2464.782829705;
+               map_P[27] = 2303.889031418;
+               map_P[28] = 2147.054385395;
+               map_P[29] = 1994.132771399;
+               map_P[30] = 1844.985347313;
+               map_P[31] = 1699.475053321;
+               map_P[32] = 1557.474019598;
+               map_P[33] = 1418.860479043;
+               map_P[34] = 1283.520126656;
+               map_P[35] = 1151.338004216;
+
+               /*
+                map_P = { 8752.218091048, 8446.106670416,
+                8107.990680283, 7776.191574285, 7455.920518777, 7146.602181352,
+                6847.709026813, 6558.734204024, 6279.213382291, 6008.702199986,
+                5746.786181029, 5493.078256495, 5247.206333097, 5008.828069358,
+                4777.615815166, 4553.258735900, 4335.470002316, 4123.971545694,
+                3918.501939675, 3718.817618538, 3524.683625800, 3335.876573044,
+                3152.188635673, 2973.421417103, 2799.382330486, 2629.892542617,
+                2464.782829705, 2303.889031418, 2147.054385395, 1994.132771399,
+                1844.985347313, 1699.475053321, 1557.474019598, 1418.860479043,
+                1283.520126656, 1151.338004216 };
+                */
+
+               MIN_THETA_R = 0.65;
+               PER_INDEX_R = 0.01;
+               MAX_THETA_R = 0.995;
+
+               map_Q = new double[36];
+               map_Q[0] = 1768.846590190;
+               map_Q[1] = 1706.229490046;
+               map_Q[2] = 1637.253873079;
+               map_Q[3] = 1569.637451623;
+               map_Q[4] = 1504.419525242;
+               map_Q[5] = 1441.477913810;
+               map_Q[6] = 1380.700660446;
+               map_Q[7] = 1321.980440476;
+               map_Q[8] = 1265.218982201;
+               map_Q[9] = 1210.322424636;
+               map_Q[10] = 1157.203306183;
+               map_Q[11] = 1105.780028163;
+               map_Q[12] = 1055.974296746;
+               map_Q[13] = 1007.714103979;
+               map_Q[14] = 960.930643875;
+               map_Q[15] = 915.558722782;
+               map_Q[16] = 871.538200178;
+               map_Q[17] = 828.810882006;
+               map_Q[18] = 787.322098340;
+               map_Q[19] = 747.020941334;
+               map_Q[20] = 707.858376214;
+               map_Q[21] = 669.787829741;
+               map_Q[22] = 632.765987756;
+               map_Q[23] = 596.751545633;
+               map_Q[24] = 561.704466609;
+               map_Q[25] = 527.587580585;
+               map_Q[26] = 494.365739051;
+               map_Q[27] = 462.004890691;
+               map_Q[28] = 430.472546686;
+               map_Q[29] = 399.738429196;
+               map_Q[30] = 369.773787595;
+               map_Q[31] = 340.550287137;
+               map_Q[32] = 312.041496095;
+               map_Q[33] = 284.222260660;
+               map_Q[34] = 257.068973074;
+               map_Q[35] = 230.557938283;
+
+               /*
+                * map_Q = { 1768.846590190, 1706.229490046, 1637.253873079,
+                * 1569.637451623, 1504.419525242, 1441.477913810, 1380.700660446,
+                * 1321.980440476, 1265.218982201, 1210.322424636, 1157.203306183,
+                * 1105.780028163, 1055.974296746, 1007.714103979, 960.930643875,
+                * 915.558722782, 871.538200178, 828.810882006, 787.322098340,
+                * 747.020941334, 707.858376214, 669.787829741, 632.765987756,
+                * 596.751545633, 561.704466609, 527.587580585, 494.365739051,
+                * 462.004890691, 430.472546686, 399.738429196, 369.773787595,
+                * 340.550287137, 312.041496095, 284.222260660, 257.068973074,
+                * 230.557938283 };
+                */
+
+               MIN_THETA_I = 0.13;
+               PER_INDEX_I = 0.002;
+               MAX_THETA_I = 0.199;
+
+               D = new Demand(0.0,0.0);
+               last = new Demand(0.0,0.0);
+
+               feeders = new Lateral[nfeeders];
+               for (int i = 0; i < nfeeders; i++) {
+                       feeders[i] = new Lateral(nlaterals, nbranches, nleaves);
+               }
+       }
+
+       /**
+        * Return true if we've reached a convergence.
+        * 
+        * @return true if we've finished.
+        **/
+       boolean reachedLimit() {
+               boolean rtr= (Math.abs(D.P / 10000.0 - theta_R) < ROOT_EPSILON && Math
+                               .abs(D.Q / 10000.0 - theta_I) < ROOT_EPSILON);
+               return rtr;
+       }
+
+       /**
+        * Pass prices down and compute demand for the power system.
+        **/
+       void compute() {
+               D.P = 0.0;
+               D.Q = 0.0;
+               
+               double pp=0.0;
+               double qq=0.0;
+               
+               for (int i = 0; i < feeders.length; i++) {
+                       Lateral lateral=feeders[i];
+                       sese parallel{
+                               DemandResult result=compute(lateral);
+                               double p=result.P;
+                               double q=result.Q;
+//                             D.increment(feeders[i].compute(theta_R, theta_I, theta_R, theta_I));
+                       }
+                       sese serial{
+                               pp+=p;
+                               qq+=q;
+                       }
+               } // end of for
+               D.P=pp;
+               D.Q=qq;
+       }
+       
+       DemandResult compute(Lateral lateral){
+               Demand demand= lateral.compute(theta_R, theta_I, theta_R, theta_I);
+               DemandResult result=new DemandResult(demand.P,demand.Q);
+               return result;
+       }
+
+       /**
+        * Set up the values for another pass of the algorithm.
+        **/
+       void nextIter(boolean verbose, double new_theta_R, double new_theta_I) {
+               last.P = D.P;
+               last.Q = D.Q;
+               last_theta_R = theta_R;
+               last_theta_I = theta_I;
+               theta_R = new_theta_R;
+               theta_I = new_theta_I;
+       }
+
+       /**
+        * Set up the values for another pass of the algorithm.
+        * 
+        * @param verbose
+        *            is set to true to print the values of the system.
+        **/
+       void nextIter(boolean verbose) {
+               int i = (int) ((theta_R - MIN_THETA_R) / PER_INDEX_R);
+               if (i < 0)
+                       i = 0;
+               if (i > 35)
+                       i = 35;
+               double d_theta_R = -(theta_R - D.P / 10000.0)
+                               / (1 - (map_P[i + 1] - map_P[i]) / (PER_INDEX_R * 10000.0));
+
+               i = (int) ((theta_I - MIN_THETA_I) / PER_INDEX_I);
+               if (i < 0)
+                       i = 0;
+               if (i > 35)
+                       i = 35;
+               double d_theta_I = -(theta_I - D.Q / 10000.0)
+                               / (1 - (map_Q[i + 1] - map_Q[i]) / (PER_INDEX_I * 10000.0));
+
+               if (verbose) {
+                       System.out.println("D TR-" + d_theta_R + ", TI=" + d_theta_I);
+               }
+
+               last.P = D.P;
+               last.Q = D.Q;
+               last_theta_R = theta_R;
+               last_theta_I = theta_I;
+               theta_R += d_theta_R;
+               theta_I += d_theta_I;
+       }
+
+       /**
+        * Create a string representation of the power plant.
+        **/
+       public String toString() {
+               return "TR=" + theta_R + ", TI=" + theta_I + ", P0=" + D.P + ", Q0="
+                               + D.Q;
+       }
+}
+
+class DemandResult{
+       
+               double P;
+               double Q;
+               
+               public DemandResult(double P, double Q){
+                       this.P=P;
+                       this.Q=Q;
+               }
+               
+}
diff --git a/Robust/src/Benchmarks/mlp/power/makefile b/Robust/src/Benchmarks/mlp/power/makefile
new file mode 100644 (file)
index 0000000..83401d3
--- /dev/null
@@ -0,0 +1,30 @@
+#raytracer
+PROGRAM=test
+
+SOURCE_FILES=Power.java
+
+BUILDSCRIPT=~/eclipse/workspaces/irvine_sep09/Robust/src/buildscript
+
+USEMLP=  -mlp 8 2  -mlpdebug  # use to turn mlp on and off and make sure rest of build not broken
+BSFLAGS=   -32bit -nooptimize -mainclass Power -debug -garbagestats 
+OWNERSHIP= -ownership -ownallocdepth 1 -enable-assertions  -methodeffects -flatirusermethods -ownwritedots final -ownaliasfile aliases.txt 
+
+default:
+       ../../../buildscript -nojava $(USEMLP) $(BSFLAGS) $(OWNERSHIP) -o $(PROGRAM)p $(SOURCE_FILES) -builddir par
+
+single:
+       ../../../buildscript $(BSFLAGS) -o $(PROGRAM)s $(SOURCE_FILES) -builddir sing
+
+java:
+       ../../../buildscript $(USEMLP) $(BSFLAGS) $(OWNERSHIP) -o $(PROGRAM)p $(SOURCE_FILES) -builddir par
+
+clean:
+       rm -f  $(PROGRAM).bin
+       rm -fr par sing
+       rm -f  *~
+       rm -f  *.dot
+       rm -f  *.png
+       rm -f  *.txt
+       rm -f  aliases.txt
+       rm -f  mlpReport*txt
+       rm -f  results*txt
diff --git a/Robust/src/Tests/disjoint/power_new/Branch.java b/Robust/src/Tests/disjoint/power_new/Branch.java
new file mode 100644 (file)
index 0000000..fcabf06
--- /dev/null
@@ -0,0 +1,108 @@
+/**
+ * A class that represents a branch node in the power pricing architecture. A
+ * branch node is another type of intermediate node that represents a split in
+ * the electrical power path. The branch nodes hang from the lateral nodes. <b>
+ * Each branch node contains a direct link to a set of customers.
+ **/
+final class Branch {
+       /**
+        * Demand for the customers supported by the branch node.
+        **/
+       Demand D;
+       double alpha;
+       double beta;
+       double R;
+       double X;
+       /**
+        * A link to the next branch node that has the same parent (lateral) node.
+        **/
+       Branch nextBranch;
+       /**
+        * A list of customers - represented a leaf nodes.
+        **/
+       Leaf[] leaves;
+
+       /**
+        * Create all the branch nodes for a single lateral node. Also, create the
+        * customers supported by this branch node
+        * 
+        * @param num
+        *            a counter to limit the branch nodes created for the lateral
+        *            node
+        * @param nleaves
+        *            the nubmer of leafs to create per branch
+        **/
+       public Branch(int num, int nleaves) {
+
+               alpha = 0.0;
+               beta = 0.0;
+               R = 0.0001;
+               X = 0.00002;
+
+               D = new Demand(0.0, 0.0);
+
+               if (num <= 1) {
+                       if (num <= 0)
+//                             throw new RuntimeException("Branch constructor with zero num");
+                               System.out.println("Branch constructor with zero num");
+                       nextBranch = null;
+               } else {
+                       nextBranch = new Branch(num - 1, nleaves);
+               }
+
+               // fill in children
+               leaves = new Leaf[nleaves];
+               for (int k = 0; k < nleaves; k++) {
+                       leaves[k] = new Leaf();
+               }
+       }
+
+       /**
+        * Pass the prices down and compute the demand for the power system.
+        * 
+        * @param theta_R
+        *            real power multiplier
+        * @param theta_I
+        *            reactive power multiplier
+        * @param pi_R
+        *            the real power price
+        * @param pi_I
+        *            the reactive power price
+        * @return the demand for the customers supported by this branch
+        **/
+       public Demand compute(double theta_R, double theta_I, double pi_R,
+                       double pi_I) {
+               double new_pi_R = pi_R + alpha * (theta_R + (theta_I * X) / R);
+               double new_pi_I = pi_I + beta * (theta_I + (theta_R * R) / X);
+
+               Demand a1 = null;
+               if (nextBranch != null) {
+                       a1 = nextBranch.compute(theta_R, theta_I, new_pi_R, new_pi_I);
+               }
+
+               // Initialize and pass the prices down the tree
+               D.reset();
+               for (int i = 0; i < leaves.length; i++) {
+                       D.increment(leaves[i].compute(new_pi_R, new_pi_I));
+               }
+               if (nextBranch != null) {
+                       D.increment(a1);
+               }
+
+               // pass demand up, P, Q
+               double a = R * R + X * X;
+               double b = 2 * R * X * D.Q - 2 * X * X * D.P - R;
+               double c = R * D.Q - X * D.P;
+               c = c * c + R * D.P;
+               double root = (-b - Math.sqrt(b * b - 4 * a * c)) / (2 * a);
+               D.Q = D.Q + ((root - D.P) * X) / R;
+               D.P = root;
+               // compute alpha, beta
+               a = 2 * R * D.P;
+               b = 2 * X * D.Q;
+               alpha = a / (1 - a - b);
+               beta = b / (1 - a - b);
+
+               return D;
+       }
+}
diff --git a/Robust/src/Tests/disjoint/power_new/Demand.java b/Robust/src/Tests/disjoint/power_new/Demand.java
new file mode 100644 (file)
index 0000000..f6b369d
--- /dev/null
@@ -0,0 +1,241 @@
+/**
+ * A class that represents power demand.
+ **/
+final class Demand {
+       /**
+        * Real power demand.
+        **/
+       public double P;
+       /**
+        * Reactive power demand.
+        **/
+       public double Q;
+
+       private static double F_EPSILON;
+       private static double G_EPSILON;
+       private static double H_EPSILON;
+
+       /**
+        * Create an object that represents power demand and initialize the power
+        * demans values.
+        * 
+        * @param toP
+        *            the real power demand
+        * @param toQ
+        *            the reactive power demand
+        **/
+       Demand(double toP, double toQ) {
+               F_EPSILON = 0.000001;
+               G_EPSILON = 0.000001;
+               H_EPSILON = 0.000001;
+
+               P = toP;
+               Q = toQ;
+       }
+
+       /**
+        * Create an empry power demand object.
+        **/
+//     Demand() {
+//             this(0.0, 0.0);
+//     }
+
+       /**
+        * Increment the demand.
+        * 
+        * @param frm
+        *            the amount to increase the demand
+        **/
+       void increment(Demand frm) {
+               P += frm.P;
+               Q += frm.Q;
+       }
+
+       /**
+        * Reset the power demand values.
+        **/
+       void reset() {
+               P = 0.0;
+               Q = 0.0;
+       }
+
+       /**
+        * Add the demand values from the two inputs.
+        * 
+        * @param a1
+        *            the demand values for operand1
+        * @param a2
+        *            the demand values for operand2
+        **/
+       void add(Demand a1, Demand a2) {
+               P = a1.P + a2.P;
+               Q = a1.Q + a2.Q;
+       }
+
+       /**
+        * Assign the demand from the specified value to this one.
+        * 
+        * @param frm
+        *            the demand assigned to this object.
+        **/
+       void assign(Demand frm) {
+               P = frm.P;
+               Q = frm.Q;
+       }
+
+       /**
+        * Calculate the power demand given the prices. The pricing problem sets the
+        * price for each customer's power consumption so that the economic
+        * efficiency of the whole community is maximied.
+        * 
+        * @param pi_R
+        *            price for real power
+        * @param pi_I
+        *            price for reactive power
+        **/
+       void optimizeNode(double pi_R, double pi_I) {
+               double[] grad_f = new double[2];
+               double[] grad_g = new double[2];
+               double[] grad_h = new double[2];
+               double[] dd_grad_f = new double[2];
+
+               double g, h;
+               do {
+                       // Move onto h=0 line
+                       h = findH();
+                       if (Math.abs(h) > H_EPSILON) {
+                               double magnitude = findGradientH(grad_h);
+                               double total = h / magnitude;
+                               P -= total * grad_h[0];
+                               Q -= total * grad_h[1];
+                       }
+
+                       // Check that g is still valid
+                       g = findG();
+                       if (g > G_EPSILON) {
+                               double magnitude = findGradientG(grad_g);
+                               findGradientH(grad_h);
+                               magnitude *= makeOrthogonal(grad_g, grad_h);
+                               double total = g / magnitude;
+                               P -= total * grad_g[0];
+                               Q -= total * grad_g[1];
+                       }
+
+                       // Maximize benefit
+                       double magnitude = findGradientF(pi_R, pi_I, grad_f);
+                       findDDGradF(pi_R, pi_I, dd_grad_f);
+                       double total = 0.0;
+                       for (int i = 0; i < 2; i++)
+                               total += grad_f[i] * dd_grad_f[i];
+                       magnitude /= Math.abs(total);
+                       findGradientH(grad_h);
+                       magnitude *= makeOrthogonal(grad_f, grad_h);
+                       findGradientG(grad_g);
+                       total = 0.0;
+                       for (int i = 0; i < 2; i++)
+                               total += grad_f[i] * grad_g[i];
+                       if (total > 0) {
+                               double max_dist = -findG() / total;
+                               if (magnitude > max_dist)
+                                       magnitude = max_dist;
+                       }
+                       P += magnitude * grad_f[0];
+                       Q += magnitude * grad_f[1];
+
+                       h = findH();
+                       g = findG();
+                       findGradientF(pi_R, pi_I, grad_f);
+                       findGradientH(grad_h);
+               } while (Math.abs(h) > H_EPSILON
+                               || g > G_EPSILON
+                               || (Math.abs(g) > G_EPSILON && Math.abs(grad_f[0] * grad_h[1]
+                                               - grad_f[1] * grad_h[0]) > F_EPSILON));
+       }
+
+       private double findG() {
+               return (P * P + Q * Q - 0.8);
+       }
+
+       private double findH() {
+               return (P - 5 * Q);
+       }
+
+       private double findGradientF(double pi_R, double pi_I, double[] gradient) {
+               gradient[0] = 1 / (1 + P) - pi_R;
+               gradient[1] = 1 / (1 + Q) - pi_I;
+
+               double magnitude = 0.0;
+               for (int i = 0; i < 2; i++)
+                       magnitude += gradient[i] * gradient[i];
+
+               magnitude = Math.sqrt(magnitude);
+
+               for (int i = 0; i < 2; i++)
+                       gradient[i] /= magnitude;
+
+               return magnitude;
+       }
+
+       private double findGradientG(double[] gradient) {
+               gradient[0] = 2 * P;
+               gradient[1] = 2 * Q;
+               double magnitude = 0.0;
+               for (int i = 0; i < 2; i++)
+                       magnitude += gradient[i] * gradient[i];
+
+               magnitude = Math.sqrt(magnitude);
+
+               for (int i = 0; i < 2; i++)
+                       gradient[i] /= magnitude;
+
+               return magnitude;
+       }
+
+       private double findGradientH(double[] gradient) {
+               gradient[0] = 1.0;
+               gradient[1] = -5.0;
+               double magnitude = 0.0;
+               for (int i = 0; i < 2; i++)
+                       magnitude += gradient[i] * gradient[i];
+               magnitude = Math.sqrt(magnitude);
+               for (int i = 0; i < 2; i++)
+                       gradient[i] /= magnitude;
+
+               return magnitude;
+       }
+
+       private void findDDGradF(double pi_R, double pi_I, double[] dd_grad) {
+               double P_plus_1_inv = 1 / (P + 1);
+               double Q_plus_1_inv = 1 / (Q + 1);
+               double P_grad_term = P_plus_1_inv - pi_R;
+               double Q_grad_term = Q_plus_1_inv - pi_I;
+
+               double grad_mag = Math.sqrt(P_grad_term * P_grad_term + Q_grad_term
+                               * Q_grad_term);
+
+               dd_grad[0] = -P_plus_1_inv * P_plus_1_inv * P_grad_term / grad_mag;
+               dd_grad[1] = -Q_plus_1_inv * Q_plus_1_inv * Q_grad_term / grad_mag;
+       }
+
+       private double makeOrthogonal(double[] v_mod, double[] v_static) {
+               double total = 0.0;
+               for (int i = 0; i < 2; i++)
+                       total += v_mod[i] * v_static[i];
+
+               double length = 0.0;
+               for (int i = 0; i < 2; i++) {
+                       v_mod[i] -= total * v_static[i];
+                       length += v_mod[i] * v_mod[i];
+               }
+               length = Math.sqrt(length);
+
+               for (int i = 0; i < 2; i++)
+                       v_mod[i] /= length;
+
+               if (1 - total * total < 0) // Roundoff error
+                       return 0;
+
+               return Math.sqrt(1 - total * total);
+       }
+
+}
diff --git a/Robust/src/Tests/disjoint/power_new/Lateral.java b/Robust/src/Tests/disjoint/power_new/Lateral.java
new file mode 100644 (file)
index 0000000..460602a
--- /dev/null
@@ -0,0 +1,108 @@
+/**
+ * A class that represents a lateral node in the power pricing problem. The
+ * lateral nodes is an intermediate node that represents a switch, tappoints, or
+ * transformer. It hangs from the root node (the power substation).
+ * <p>
+ * Each lateral node is the head in a line of branch nodes.
+ **/
+final class Lateral {
+       /**
+        * Demand for the customers supported by the lateral node.
+        **/
+       Demand D;
+       double alpha;
+       double beta;
+       double R;
+       double X;
+       /**
+        * The next lateral that shares the same parent (root) node.
+        **/
+       Lateral next_lateral;
+       /**
+        * The branch nodes that are supported by the lateral node.
+        **/
+       Branch branch;
+
+       /**
+        * Create all the lateral nodes for a single root node.
+        * 
+        * @param num
+        *            the child number of the lateral wrt the root
+        * @param nbranches
+        *            the number of branch nodes per lateral.
+        * @param nleaves
+        *            the number of leaf nodes per branch.
+        **/
+       Lateral(int num, int nbranches, int nleaves) {
+
+               alpha = 0.0;
+               beta = 0.0;
+               R = 1 / 300000.0;
+               X = 0.000001;
+
+               D = new Demand(0.0,0.0);
+
+               // create a linked list of the lateral nodes
+               if (num <= 1) {
+                       if (num <= 0)
+//                             throw new RuntimeException("Lateral constructor with zero num");
+                               System.out.println("Lateral constructor with zero num");
+                       next_lateral = null;
+               } else {
+                       next_lateral = new Lateral(num - 1, nbranches, nleaves);
+               }
+
+               // create the branch nodes
+               branch = new Branch(nbranches, nleaves);
+       }
+
+       /**
+        * Pass prices down and compute demand for the power system.
+        * 
+        * @param theta_R
+        *            real power demand multiplier
+        * @param theta_I
+        *            reactive power demand multiplier
+        * @param pi_R
+        *            price of real power demand
+        * @param pi_I
+        *            price of reactive power demand
+        * @return the demand for the customers supported by this lateral
+        **/
+       Demand compute(double theta_R, double theta_I, double pi_R, double pi_I) {
+               // generate the new prices and pass them down to the customers
+               double new_pi_R = pi_R + alpha * (theta_R + (theta_I * X) / R);
+               double new_pi_I = pi_I + beta * (theta_I + (theta_R * R) / X);
+
+               Demand a1;
+               if (next_lateral != null)
+                       a1 = next_lateral.compute(theta_R, theta_I, new_pi_R, new_pi_I);
+               else
+                       a1 = null;
+
+               Demand a2 = branch.compute(theta_R, theta_I, new_pi_R, new_pi_I);
+
+               if (next_lateral != null) {
+                       D.add(a1, a2);
+               } else {
+                       D.assign(a2);
+               }
+
+               // compute the new power demand values P,Q
+               double a = R * R + X * X;
+               double b = 2 * R * X * D.Q - 2 * X * X * D.P - R;
+               double c = R * D.Q - X * D.P;
+               c = c * c + R * D.P;
+               double root = (-b - Math.sqrt(b * b - 4 * a * c)) / (2 * a);
+               D.Q = D.Q + ((root - D.P) * X) / R;
+               D.P = root;
+
+               // compute alpha, beta
+               a = 2 * R * D.P;
+               b = 2 * X * D.Q;
+               alpha = a / (1 - a - b);
+               beta = b / (1 - a - b);
+               
+               return D;
+       }
+}
diff --git a/Robust/src/Tests/disjoint/power_new/Leaf.java b/Robust/src/Tests/disjoint/power_new/Leaf.java
new file mode 100644 (file)
index 0000000..5867a57
--- /dev/null
@@ -0,0 +1,38 @@
+/**
+ * A class that represents a customer in the power system optimization problem.
+ * A customer is a leaf node in tree representation of the problem.
+ **/
+final class Leaf {
+       /**
+        * Power demand for the customer
+        **/
+       Demand D;
+       /**
+        * Price for real power demand
+        **/
+       double pi_R;
+       /**
+        * Price for reaactive power demand
+        **/
+       double pi_I;
+
+       Leaf() {
+               D = new Demand(1.0, 1.0);
+       }
+
+       /**
+        * Pass prices down and compute demand for the customer.
+        * 
+        * @return the power demand for the customer
+        **/
+       Demand compute(double pi_R, double pi_I) {
+               D.optimizeNode(pi_R, pi_I);
+
+               if (D.P < 0.0) {
+                       D.P = 0.0;
+                       D.Q = 0.0;
+               }
+               return D;
+       }
+
+}
diff --git a/Robust/src/Tests/disjoint/power_new/Power.java b/Robust/src/Tests/disjoint/power_new/Power.java
new file mode 100644 (file)
index 0000000..cae2902
--- /dev/null
@@ -0,0 +1,100 @@
+/**
+ * A Java implementation of the <tt>power</tt> Olden benchmark. The original
+ * algorithm is from the following paper:
+ * <p>
+ * <cite> S. Lumetta, L. Murphy, X. Li, D. Culler, and I. Khalil. "Decentralized
+ * optimal power pricing: The development of a parallel program." Supercomputing
+ * '93, 243-249 </cite>
+ * <p>
+ * Note - the number of customers is fixed at 10,000 for this benchmark. We
+ * create a data structure that contains 1 root (the (power substation). There
+ * are 10 main feeders from the root and each feeder branches to 20 lateral
+ * nodes. Each lateral node is the head of a line of five branch nodes and each
+ * branch has 10 customers. In total, there are 10,000 customers (and 1201
+ * internal nodes).
+ * <p>
+ * The power pricing problems sets the price of each customer's power
+ * consumption so that the economic efficiency of the whole community is
+ * maximized.
+ **/
+public class Power {
+       /**
+        * Should we print the results as we run the benchmark
+        **/
+//     static boolean printResults;
+       /**
+        * Print information messages?
+        **/
+//     static boolean printMsgs;
+
+       /**
+        * The main routine which creates the power network and runs the simulation
+        * 
+        * @param args
+        *            the command line args
+        **/
+       public static void main(String args[]) {
+
+               boolean printResults = true;
+               boolean printMsgs =true;
+               // the input size is fixed, but the user may want the result printed
+               // parseCmdLine(args);
+
+               // initial pass
+               long start0 = System.currentTimeMillis();
+               Root r = new Root(10, 20, 5, 10);
+               long end0 = System.currentTimeMillis();
+
+               long start1 = System.currentTimeMillis();
+               r.compute();
+               r.nextIter(false, 0.7, 0.14);
+
+               while (true) {
+                       r.compute();
+                       if (printResults)
+                               System.out.println(r);
+
+                       if (r.reachedLimit())
+                               break;
+
+                       r.nextIter(printResults);
+               } /* while */
+
+               long end1 = System.currentTimeMillis();
+
+               if (printMsgs) {
+                       System.out.println("Power build time " + (end0 - start0) / 1000.0);
+                       System.out
+                                       .println("Power compute time " + (end1 - start1) / 1000.0);
+                       System.out.println("Power total time " + (end1 - start0) / 1000.0);
+               }
+               System.out.println("Done!");
+       }
+
+       /**
+        * Parse the command line options.
+        * 
+        * @param args
+        *            the command line options.
+        **/
+       /*
+        * private static final void parseCmdLine(String args[]) { int i = 0; String
+        * arg;
+        * 
+        * while (i < args.length && args[i].startsWith("-")) { arg = args[i++]; if
+        * (arg.equals("-h")) { usage(); } else if (arg.equals("-p")) { printResults
+        * = true; } else if (arg.equals("-m")) { printMsgs = true; } } }
+        */
+
+       /**
+        * The usage routine which describes the program options.
+        **/
+       private static final void usage() {
+               System.out.println("usage: java Power [-p] [-m] [-h]");
+               System.out.println("    -p (print results)");
+               System.out.println("    -m (print informative messages)");
+               System.out.println("    -h (this message)");
+               System.exit(0);
+       }
+
+}
diff --git a/Robust/src/Tests/disjoint/power_new/Root.java b/Robust/src/Tests/disjoint/power_new/Root.java
new file mode 100644 (file)
index 0000000..3663a6f
--- /dev/null
@@ -0,0 +1,314 @@
+import com.enea.jcarder.transactionalinterfaces.HashMap;
+
+import dstm2.AtomicSuperClass;
+
+/**
+ * The root node of the power system optimization tree. The root node represents
+ * the power plant.
+ **/
+final class Root {
+       /**
+        * Total system power demand.
+        **/
+       Demand D;
+       
+       double P,Q;
+       /**
+        * Lagrange multiplier for the global real power equality constraint
+        **/
+       double theta_R;
+       /**
+        * Lagrange multiplier for the global reactive power equality constraint
+        **/
+       double theta_I;
+       /**
+        * The power demand on the previous iteration
+        **/
+       Demand last;
+       /**
+        * The real power equality constraint on the previous iteration
+        **/
+       double last_theta_R;
+       /**
+        * The reactive power equality constraint on the previous iteration
+        **/
+       double last_theta_I;
+       /**
+        * A representation of the customers that feed off of the power plant.
+        **/
+       Lateral[] feeders;
+
+       /**
+        * Value used to compute convergence
+        **/
+       private static double ROOT_EPSILON;
+
+       /**
+        * Domain of thetaR->P map is 0.65 to 1.00 [index*0.01+0.65]
+        **/
+       private static double map_P[];
+
+       private static double MIN_THETA_R;
+       private static double PER_INDEX_R;
+       private static double MAX_THETA_R;
+
+       /**
+        * Domain of thetaI->Q map is 0.130 to 0.200 [index*0.002+0.130]
+        **/
+       private static double map_Q[];
+
+       private static double MIN_THETA_I;
+       private static double PER_INDEX_I;
+       private static double MAX_THETA_I;
+       
+       /**
+        * Create the tree used by the power system optimization benchmark. Each
+        * root contains <tt>nfeeders</tt> feeders which each contain
+        * <tt>nlaterals</tt> lateral nodes, which each contain <tt>nbranches</tt>
+        * branch nodes, which each contain <tt>nleafs</tt> leaf nodes.
+        * 
+        * @param nfeeders
+        *            the number of feeders off of the root
+        * @param nlaterals
+        *            the number of lateral nodes per feeder
+        * @param nbranches
+        *            the number of branches per lateral
+        * @param nleaves
+        *            the number of leaves per branch
+        **/
+       Root(int nfeeders, int nlaterals, int nbranches, int nleaves) {
+
+               theta_R = 0.8;
+               theta_I = 0.16;
+               ROOT_EPSILON = 0.00001;
+               map_P = new double[36];
+
+               map_P[0] = 8752.218091048;
+               map_P[1] = 8446.106670416;
+               map_P[2] = 8107.990680283;
+               map_P[3] = 7776.191574285;
+               map_P[4] = 7455.920518777;
+               map_P[5] = 7146.602181352;
+               map_P[6] = 6847.709026813;
+               map_P[7] = 6558.734204024;
+               map_P[8] = 6279.213382291;
+               map_P[9] = 6008.702199986;
+               map_P[10] = 5746.786181029;
+               map_P[11] = 5493.078256495;
+               map_P[12] = 5247.206333097;
+               map_P[13] = 5008.828069358;
+               map_P[14] = 4777.615815166;
+               map_P[15] = 4553.258735900;
+               map_P[16] = 4335.470002316;
+               map_P[17] = 4123.971545694;
+               map_P[18] = 3918.501939675;
+               map_P[19] = 3718.817618538;
+               map_P[20] = 3524.683625800;
+               map_P[21] = 3335.876573044;
+               map_P[22] = 3152.188635673;
+               map_P[23] = 2973.421417103;
+               map_P[24] = 2799.382330486;
+               map_P[25] = 2629.892542617;
+               map_P[26] = 2464.782829705;
+               map_P[27] = 2303.889031418;
+               map_P[28] = 2147.054385395;
+               map_P[29] = 1994.132771399;
+               map_P[30] = 1844.985347313;
+               map_P[31] = 1699.475053321;
+               map_P[32] = 1557.474019598;
+               map_P[33] = 1418.860479043;
+               map_P[34] = 1283.520126656;
+               map_P[35] = 1151.338004216;
+
+               /*
+                map_P = { 8752.218091048, 8446.106670416,
+                8107.990680283, 7776.191574285, 7455.920518777, 7146.602181352,
+                6847.709026813, 6558.734204024, 6279.213382291, 6008.702199986,
+                5746.786181029, 5493.078256495, 5247.206333097, 5008.828069358,
+                4777.615815166, 4553.258735900, 4335.470002316, 4123.971545694,
+                3918.501939675, 3718.817618538, 3524.683625800, 3335.876573044,
+                3152.188635673, 2973.421417103, 2799.382330486, 2629.892542617,
+                2464.782829705, 2303.889031418, 2147.054385395, 1994.132771399,
+                1844.985347313, 1699.475053321, 1557.474019598, 1418.860479043,
+                1283.520126656, 1151.338004216 };
+                */
+
+               MIN_THETA_R = 0.65;
+               PER_INDEX_R = 0.01;
+               MAX_THETA_R = 0.995;
+
+               map_Q = new double[36];
+               map_Q[0] = 1768.846590190;
+               map_Q[1] = 1706.229490046;
+               map_Q[2] = 1637.253873079;
+               map_Q[3] = 1569.637451623;
+               map_Q[4] = 1504.419525242;
+               map_Q[5] = 1441.477913810;
+               map_Q[6] = 1380.700660446;
+               map_Q[7] = 1321.980440476;
+               map_Q[8] = 1265.218982201;
+               map_Q[9] = 1210.322424636;
+               map_Q[10] = 1157.203306183;
+               map_Q[11] = 1105.780028163;
+               map_Q[12] = 1055.974296746;
+               map_Q[13] = 1007.714103979;
+               map_Q[14] = 960.930643875;
+               map_Q[15] = 915.558722782;
+               map_Q[16] = 871.538200178;
+               map_Q[17] = 828.810882006;
+               map_Q[18] = 787.322098340;
+               map_Q[19] = 747.020941334;
+               map_Q[20] = 707.858376214;
+               map_Q[21] = 669.787829741;
+               map_Q[22] = 632.765987756;
+               map_Q[23] = 596.751545633;
+               map_Q[24] = 561.704466609;
+               map_Q[25] = 527.587580585;
+               map_Q[26] = 494.365739051;
+               map_Q[27] = 462.004890691;
+               map_Q[28] = 430.472546686;
+               map_Q[29] = 399.738429196;
+               map_Q[30] = 369.773787595;
+               map_Q[31] = 340.550287137;
+               map_Q[32] = 312.041496095;
+               map_Q[33] = 284.222260660;
+               map_Q[34] = 257.068973074;
+               map_Q[35] = 230.557938283;
+
+               /*
+                * map_Q = { 1768.846590190, 1706.229490046, 1637.253873079,
+                * 1569.637451623, 1504.419525242, 1441.477913810, 1380.700660446,
+                * 1321.980440476, 1265.218982201, 1210.322424636, 1157.203306183,
+                * 1105.780028163, 1055.974296746, 1007.714103979, 960.930643875,
+                * 915.558722782, 871.538200178, 828.810882006, 787.322098340,
+                * 747.020941334, 707.858376214, 669.787829741, 632.765987756,
+                * 596.751545633, 561.704466609, 527.587580585, 494.365739051,
+                * 462.004890691, 430.472546686, 399.738429196, 369.773787595,
+                * 340.550287137, 312.041496095, 284.222260660, 257.068973074,
+                * 230.557938283 };
+                */
+
+               MIN_THETA_I = 0.13;
+               PER_INDEX_I = 0.002;
+               MAX_THETA_I = 0.199;
+
+               D = new Demand(0.0,0.0);
+               last = new Demand(0.0,0.0);
+
+               feeders = new Lateral[nfeeders];
+               for (int i = 0; i < nfeeders; i++) {
+                       feeders[i] = new Lateral(nlaterals, nbranches, nleaves);
+               }
+       }
+
+       /**
+        * Return true if we've reached a convergence.
+        * 
+        * @return true if we've finished.
+        **/
+       boolean reachedLimit() {
+               boolean rtr= (Math.abs(D.P / 10000.0 - theta_R) < ROOT_EPSILON && Math
+                               .abs(D.Q / 10000.0 - theta_I) < ROOT_EPSILON);
+               return rtr;
+       }
+
+       /**
+        * Pass prices down and compute demand for the power system.
+        **/
+       void compute() {
+               D.P = 0.0;
+               D.Q = 0.0;
+               
+               double pp=0.0;
+               double qq=0.0;
+               
+               for (int i = 0; i < feeders.length; i++) {
+                       Lateral lateral=feeders[i];
+                       sese parallel{
+                               DemandResult result=compute(lateral);
+                               double p=result.P;
+                               double q=result.Q;
+//                             D.increment(feeders[i].compute(theta_R, theta_I, theta_R, theta_I));
+                       }
+                       sese serial{
+                               pp+=p;
+                               qq+=q;
+                       }
+               } // end of for
+               D.P=pp;
+               D.Q=qq;
+       }
+       
+       DemandResult compute(Lateral lateral){
+               Demand demand= lateral.compute(theta_R, theta_I, theta_R, theta_I);
+               DemandResult result=new DemandResult(demand.P,demand.Q);
+               return result;
+       }
+
+       /**
+        * Set up the values for another pass of the algorithm.
+        **/
+       void nextIter(boolean verbose, double new_theta_R, double new_theta_I) {
+               last.P = D.P;
+               last.Q = D.Q;
+               last_theta_R = theta_R;
+               last_theta_I = theta_I;
+               theta_R = new_theta_R;
+               theta_I = new_theta_I;
+       }
+
+       /**
+        * Set up the values for another pass of the algorithm.
+        * 
+        * @param verbose
+        *            is set to true to print the values of the system.
+        **/
+       void nextIter(boolean verbose) {
+               int i = (int) ((theta_R - MIN_THETA_R) / PER_INDEX_R);
+               if (i < 0)
+                       i = 0;
+               if (i > 35)
+                       i = 35;
+               double d_theta_R = -(theta_R - D.P / 10000.0)
+                               / (1 - (map_P[i + 1] - map_P[i]) / (PER_INDEX_R * 10000.0));
+
+               i = (int) ((theta_I - MIN_THETA_I) / PER_INDEX_I);
+               if (i < 0)
+                       i = 0;
+               if (i > 35)
+                       i = 35;
+               double d_theta_I = -(theta_I - D.Q / 10000.0)
+                               / (1 - (map_Q[i + 1] - map_Q[i]) / (PER_INDEX_I * 10000.0));
+
+               if (verbose) {
+                       System.out.println("D TR-" + d_theta_R + ", TI=" + d_theta_I);
+               }
+
+               last.P = D.P;
+               last.Q = D.Q;
+               last_theta_R = theta_R;
+               last_theta_I = theta_I;
+               theta_R += d_theta_R;
+               theta_I += d_theta_I;
+       }
+
+       /**
+        * Create a string representation of the power plant.
+        **/
+       public String toString() {
+               return "TR=" + theta_R + ", TI=" + theta_I + ", P0=" + D.P + ", Q0="
+                               + D.Q;
+       }
+}
+
+class DemandResult{
+       
+               double P;
+               double Q;
+               
+               public DemandResult(double P, double Q){
+                       this.P=P;
+                       this.Q=Q;
+               }
+               
+}
diff --git a/Robust/src/Tests/disjoint/power_new/makefile b/Robust/src/Tests/disjoint/power_new/makefile
new file mode 100644 (file)
index 0000000..bb8651d
--- /dev/null
@@ -0,0 +1,29 @@
+BUILDSCRIPT=../../../buildscript
+MAINCLASS=Power
+
+#DEBUGFLAGS= -disjoint-debug-callsite MDRunner t3 100
+#DEBUGFLAGS= -disjoint-debug-callsite calcGoodFeature calcGoodFeatureTask 100
+#DEBUGFLAGS= -disjoint-debug-callsite getRows calcGoodFeature 4
+#DEBUGFLAGS= -disjoint-debug-callsite setKMeans t3 500
+
+#SNAPFLAGS= -disjoint-debug-snap-method calcGoodFeatureTask 5 10 true
+#SNAPFLAGS= -disjoint-debug-snap-method calcGoodFeature 5 1 true
+
+#SNAPFLAGS= -disjoint-debug-snap-method t3 5 20 true
+
+BSFLAGS= -justanalyze -disjoint -disjoint-k 1 -disjoint-write-dots all -disjoint-alias-file aliases.txt normal -enable-assertions -mainclass ${MAINCLASS}
+
+all:
+       $(BUILDSCRIPT) $(BSFLAGS) $(DEBUGFLAGS) $(SNAPFLAGS) *.java
+
+clean:
+       rm -f  *.bin
+       rm -fr tmpbuilddirectory
+       rm -f  *~
+       rm -f  *.dot
+       rm -f  *.png
+       rm -f  *.aux
+       rm -f  *.log
+       rm -f  *.pdf
+       rm -f  aliases.txt
+       rm -f  tabResults.tex