/*
* File name: PrimeProperties.java (package eas.miscellaneous.primeProperties)
* Author(s): lko
* Java version: 7.0
* Generation date: 02.11.2012 (16:23:25)
*
* (c) This file and the EAS (Easy Agent Simulation) framework containing it
* is protected by Creative Commons by-nc-sa license. Any altered or
* further developed versions of this file have to meet the agreements
* stated by the license conditions.
*
* In a nutshell
* -------------
* You are free:
* - to Share -- to copy, distribute and transmit the work
* - to Remix -- to adapt the work
*
* Under the following conditions:
* - Attribution -- You must attribute the work in the manner specified by the
* author or licensor (but not in any way that suggests that they endorse
* you or your use of the work).
* - Noncommercial -- You may not use this work for commercial purposes.
* - Share Alike -- If you alter, transform, or build upon this work, you may
* distribute the resulting work only under the same or a similar license to
* this one.
*
* + Detailed license conditions (Germany):
* http://creativecommons.org/licenses/by-nc-sa/3.0/de/
* + Detailed license conditions (unported):
* http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en
*
* This header must be placed in the beginning of any version of this file.
*/
package eas.users.lukas.primeProperties;
import java.math.BigInteger;
import java.util.LinkedList;
import java.util.List;
import eas.miscellaneous.StaticMethods;
import eas.plugins.masterScheduler.AbstractDefaultMaster;
import eas.simulation.ConstantsSimulation;
import eas.simulation.Wink;
import eas.simulation.standardEnvironments.DummyEnvironment;
import eas.startSetup.ParCollection;
import eas.startSetup.SingleParameter;
import eas.startSetup.parameterDatatypes.Datatypes;
/**
* @author lko
*/
public class PrimeProperties extends AbstractDefaultMaster<DummyEnvironment> {
/**
*
*/
private static final long serialVersionUID = 1087600085150910855L;
@Override
public List<SingleParameter> getParameters() {
List<SingleParameter> list = super.getParameters();
list.add(new SingleParameter("base", Datatypes.integerRange(2, 36), 10, "Basis", this.id().toUpperCase()));
return list;
}
private LinkedList<String> findLukePrimesOneLonger(LinkedList<String> nums, int base) {
LinkedList<String> newSet = new LinkedList<String>();
while (!nums.isEmpty()) {
String num = nums.getFirst();
for (int i = 1; i < base; i++) {
String newNum = new BigInteger("" + i).toString(base) + num;
if (new BigInteger(newNum, base).isProbablePrime(10)) {
newSet.add(newNum);
}
}
nums.removeFirst();
}
return newSet;
}
private LinkedList<String> set = new LinkedList<String>();
private LinkedList<String> speicherArray = new LinkedList<String>();
@Override
public synchronized void runDuringSimulation(DummyEnvironment env,
Wink simZyk, ParCollection params) {
super.runDuringSimulation(env, simZyk, params);
// String elemente = "";
set = this.findLukePrimesOneLonger(set, params.getParValueInt("base"));
// if (set.size() < 100) {
// elemente = set.toString();
// }
String els = set.size() + ""; // + ": " + elemente;
params.logInfo(set.size() + "");
speicherArray.add(els);
StaticMethods.speichereTextAusArray(".", "LukesPrimes" + params.getParValueInt("base") + ".txt", speicherArray, params);
}
@Override
public void runBeforeSimulation(DummyEnvironment umg,
ParCollection params) {
super.runBeforeSimulation(umg, params);
set.add("");
}
@Override
public DummyEnvironment[] generateRunnables(ParCollection params) {
return new DummyEnvironment[] {new DummyEnvironment(0, params)};
}
@Override
public String id() {
return ConstantsSimulation.DEFAULT_MASTER_SCHEDULER_ID + "-lukesPrimes";
}
@Override
public boolean isTerminationRequested(DummyEnvironment runnable,
Wink currentTime, ParCollection params) {
return set.isEmpty();
}
}