/* -------------------------------------------------------------------------- */ /* */ /* ARM DATA GENERATOR MODEL */ /* Frans Coenen */ /* Wednesday 6 May 2006 */ /* Revissions: Tuesday 6 February 2007 */ /* */ /* -------------------------------------------------------------------------- */ /* ARM data generator GUI model for ARM experiments. */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.io.*; import java.util.*; public class GeneratorModel extends JFrame { /* ------ FIELDS ------ */ // CONSTANTS /* None */ // DATA STRUCTURES /** Density array. */ private double[] densityArray = null; /** 2-D array to hold data. */ private short[][] dataArray = null; /** 2-D arrau to hold temporary data. */ private short[][] tempDataArray = null; // OTHER FIELDS /** Number of columns. */ private int numberOfColumns = 0; /** Number of rows. */ private int numberOfRows = 0; /** Density. */ private int density = 0; /** Number of "1"s generated. */ private int attributeCounter = 0; /** Output directory file name. */ private String outputDirectoryName = null; /** File stem fo r iamge file name. */ private String fileStem = null; /** Output data file name. */ private String outputFileName = null; /** Instance of PrintWriter class */ private PrintWriter fileOutput; // SETTINGS /** 2-D Array of batch mode parameter values.
First dimension ordered as
follows: (a) Number of columns, (b) Number of rows and (c) Density.
Second dimension ordered as follows: (a) start, (b) end and
(c) step. */
private int[][] batchValues = {{100,101,10},{10000,10001,10},{5,50,5}};
/* --------------------------------------------------- */
/* */
/* CONSTRUCTORS */
/* */
/* --------------------------------------------------- */
/** Zero argument constructor. */
public GeneratorModel() {
}
/* ---------------------------------------------- */
/* */
/* METHODS */
/* */
/* ---------------------------------------------- */
/** Commences the process of generating the ARM data with a maximum of
100 attempts to get the desired density.
@param textArea instance of class JTextArea for output. */
public void generateData(JTextArea textArea) {
double newDensity = 0.0;
double tempDensity = 1000.0;
double min = ((double) density) - 0.5;
double max = ((double) density) + 0.5;
//System.out.println("min = " + min + ", max = " + max);
// Commence generation (up to 10 goes).
int index=0;
for(;index<10;index++) {
// Dimension data array
dataArray = new short[numberOfRows][numberOfColumns];
// Create density array
setDensityArray();
// Set attribute counter (counts number of 1s)
attributeCounter=0;
// Generate a data set
newDensity = generateData2();
//System.out.println("(" + index + ") newDensity = " + newDensity);
// Test accuracy
if (newDensity>=min && newDensity<=max) {
//System.out.println("BREAK");
break;
}
else {
double diff1 = Math.abs(density-newDensity);
double diff2 = Math.abs(density-tempDensity);
//System.out.println("diff1 = " + diff1 + ", diff2 = " + diff2);
if (diff1