Browse files

Madness Wizardry

I'm sorry, there is not other description for these classes.
They're temporary, I promise.
  • Loading branch information...
1 parent c9e3625 commit 70c6d4e12e13b0590de9f704b63e6276c46b9e1e @javajawa committed Mar 18, 2012
View
46 src/networkssim/NetworksSim.java
@@ -1,5 +1,7 @@
package networkssim;
+import java.io.IOException;
+import java.io.PrintStream;
import networkssim.entropy.Distribution;
import networkssim.entropy.implementations.Poisson;
import networkssim.sets.Domain;
@@ -14,23 +16,32 @@
* @param args the command line arguments
*/
@SuppressWarnings({"UseOfSystemOutOrSystemErr", "CallToThreadRun"})
- public static void main(String[] args)
+ public static void main(String[] args) throws IOException
{
- for (Double lambda : new DoubleRange(0.01, 0.25, 0.01))
+ PrintStream p = new PrintStream("Z:/tmp/networks4/new-fine.tsv");
+
+ for (Integer i : new IntRange(0, 500))
+ {
+ for (Double lambda : new DoubleRange(0.01, 0.40, 0.0025))
{
- SlottedAloha sim = new SlottedAloha(new Poisson(lambda), constDist(0.2), 50000);
+ SlottedAloha sim = new SlottedAloha(new Poisson(lambda), optimalDist(lambda), 10000);
sim.run();
QueueStatistic blockingStatistics = sim.getBlockingStatistics();
- System.out.format("l: %5$8.4f\tA: %1$10d\tC: %2$10d\tQm: %3$6.3f\tQv: %4$6.3f\n",
+ p.format("%5$6.4f\t%1$7d\t%2$7d\t%3$8.3f\n",
blockingStatistics.arrivals(),
blockingStatistics.completions(),
blockingStatistics.sampleMean(),
blockingStatistics.sampleVariance(),
lambda
);
+ System.gc();
}
+ p.flush();
+ System.out.print('.');
+ }
+ p.close();
}
private static Distribution<Integer> constDist(final double v)
@@ -40,7 +51,32 @@ public static void main(String[] args)
@Override
public Double valueOf(Integer value)
{
- return Math.E / value;
+ return v;
+ }
+
+ @Override
+ public Domain<Integer> domain()
+ {
+ return new IntRange(0, Integer.MAX_VALUE);
+ }
+
+ @Override
+ public Domain<Double> range()
+ {
+ return new DoubleRange(0.0D, 1.0D, Double.MIN_NORMAL);
+ }
+
+ };
+ }
+
+ private static Distribution<Integer> optimalDist(final double v)
+ {
+ return new Distribution<Integer>()
+ {
+ @Override
+ public Double valueOf(Integer value)
+ {
+ return (1 - v) / value;
}
@Override
View
8 src/networkssim/ResultAggregator.java
@@ -23,19 +23,19 @@
@SuppressWarnings("UseOfSystemOutOrSystemErr")
public static void main(String[] args) throws IOException
{
- final BufferedReader f = new BufferedReader(new FileReader("Z:/tmp/megaout"));
+ final BufferedReader f = new BufferedReader(new FileReader("Z:/tmp/networks4/new-fine.tsv"));
while (f.ready())
process(f.readLine());
f.close();
- final BufferedWriter w = new BufferedWriter(new FileWriter("Z:/tmp/aggregate"));
+ final BufferedWriter w = new BufferedWriter(new FileWriter("Z:/tmp/networks4/new-fine.tsv"));
for (Integer i : queue.keySet())
{
w.append(String.format("%5.4f\t%10.4f\t%10.4f\t%10.4f\t%10.4f\t%10.4f\t%10.4f\n",
- (double)i/100,
+ (double)i/10000,
arrivals.get(i).sampleMean(),
Math.sqrt(arrivals.get(i).sampleVariance()) * 1.96,
completions.get(i).sampleMean(),
@@ -53,7 +53,7 @@ private static void process(String readLine)
Matcher m = p.matcher(readLine);
m.find();
- int i = ((Double)(Double.valueOf(m.group()) * 100)).intValue();
+ int i = ((Double)(Double.valueOf(m.group()) * 10000)).intValue();
m.find();
mapSample(arrivals, i, Integer.parseInt(m.group()));
View
74 src/networkssim/ResultAggregator2Free.java
@@ -5,8 +5,11 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -16,31 +19,45 @@
public class ResultAggregator2Free
{
- static final TreeMap<Integer, Map<Integer, Sample>> arrivals = new TreeMap<Integer, Map<Integer, Sample>>();
- static final TreeMap<Integer, Map<Integer, Sample>> completions = new TreeMap<Integer, Map<Integer, Sample>>();
- static final TreeMap<Integer, Map<Integer, RealsSample>> queue = new TreeMap<Integer, Map<Integer, RealsSample>>();
+ static final TreeMap<Integer, Map<Integer, Statistic<Integer>>> arrivals = new TreeMap<Integer, Map<Integer, Statistic<Integer>>>();
+ static final TreeMap<Integer, Map<Integer, Statistic<Integer>>> completions = new TreeMap<Integer, Map<Integer, Statistic<Integer>>>();
+ static final TreeMap<Integer, Map<Integer, Statistic<Double>>> queue = new TreeMap<Integer, Map<Integer, Statistic<Double>>>();
static final Pattern p = Pattern.compile("([0-9.]+)", Pattern.CASE_INSENSITIVE);
@SuppressWarnings("UseOfSystemOutOrSystemErr")
public static void main(String[] args) throws IOException
{
- final BufferedReader f = new BufferedReader(new FileReader("Z:/tmp/megaout"));
+ final BufferedReader f = new BufferedReader(new FileReader("Z:/tmp/networks4/betas.tsv"));
+ long i = 0;
while (f.ready())
- process(f.readLine());
+ try
+ {
+ ++i;
+ process(f.readLine());
+ }
+ catch (Throwable ex)
+ {
+ throw new Error("Error on line " + i, ex);
+ }
+
f.close();
- final BufferedWriter w = new BufferedWriter(new FileWriter("Z:/tmp/aggregate"));
+ final BufferedWriter w = new BufferedWriter(new FileWriter("Z:/tmp/networks4/betas-aggregate.tsv"));
output(w, queue);
+ output(w, completions);
+ output(w, arrivals);
w.close();
+ System.out.println(i + " lines processed");
}
private static void process(String readLine)
{
+ if (readLine.trim().length() == 0) return;
Matcher m = p.matcher(readLine);
m.find();
@@ -55,49 +72,66 @@ private static void process(String readLine)
mapSample(queue, i, j, Double.parseDouble(m.group()));
}
- static <T,U> void mapSample(Map<T, Map<U, Sample>> m, T t, U u, int s)
+ static <T,U> void mapSample(Map<T, Map<U, Statistic<Integer>>> m, T t, U u, int s)
{
if (!m.containsKey(t))
- m.put(t, new TreeMap<U, Sample>());
+ m.put(t, new TreeMap<U, Statistic<Integer>>());
if (!m.get(t).containsKey(u))
- m.get(t).put(u, new Sample());
+ m.get(t).put(u, (Statistic<Integer>)new Sample());
m.get(t).get(u).observed(s);
}
- static <T,U> void mapSample(Map<T, Map<U, RealsSample>> m, T t, U u, double s)
+ static <T,U> void mapSample(Map<T, Map<U, Statistic<Double>>> m, T t, U u, double s)
{
if (!m.containsKey(t))
- m.put(t, new TreeMap<U, RealsSample>());
+ m.put(t, new TreeMap<U, Statistic<Double>>());
if (!m.get(t).containsKey(u))
m.get(t).put(u, new RealsSample());
m.get(t).get(u).observed(s);
}
- private static void output(BufferedWriter w, TreeMap<Integer, Map<Integer, RealsSample>> m) throws IOException
+ private static <T extends Number> void output(BufferedWriter w, Map<Integer, Map<Integer, Statistic<T> > > m) throws IOException
{
- for (Integer j : m.firstEntry().getValue().keySet())
+ Set<Integer> keySet = new HashSet<Integer>(Arrays.asList(1,2,4,8)); //m.values().iterator().next().keySet();
+ for (Integer j : keySet)
w.append(String.format("\t%10.4f",(double)j/100));
w.append('\n');
- for (Entry<Integer, Map<Integer, RealsSample>> n : m.entrySet())
+ for (Entry<Integer, Map<Integer, Statistic<T>>> n : m.entrySet())
{
w.append(String.format("%5.4f", (double)n.getKey()/100));
- for (Statistic<Double> s : n.getValue().values())
- w.append(String.format("\t%10.4f", s.sampleMean()));
+ for (Integer i : keySet)
+ if (!n.getValue().containsKey(i))
+ {
+ w.append('\t');
+ }
+ else
+ {
+ Statistic<T> s = n.getValue().get(i);
+ w.append(String.format("\t%10.4f", s.sampleMean()));
+ }
w.newLine();
}
w.newLine();
- for (Entry<Integer, Map<Integer, RealsSample>> n : m.entrySet())
+ for (Entry<Integer, Map<Integer, Statistic<T>>> n : m.entrySet())
{
w.append(String.format("%5.4f", (double)n.getKey()/100));
- for (Statistic<Double> s : n.getValue().values())
- w.append(String.format("\t%10.4f", Math.sqrt(s.sampleVariance()) * 1.96));
+ for (Integer i : keySet)
+ if (!n.getValue().containsKey(i))
+ {
+ w.append('\t');
+ }
+ else
+ {
+ Statistic<T> s = n.getValue().get(i);
+ w.append(String.format("\t%10.4f", Math.sqrt(s.sampleVariance()) * 1.96));
+ }
w.newLine();
}
+ w.newLine();
}
-
private ResultAggregator2Free()
{
}

0 comments on commit 70c6d4e

Please sign in to comment.