1 package org.drools.jsr94.benchmark; 2 3 /* 4 $Id: MannersDat.java,v 1.1 2003/03/22 00:57:26 tdiesler Exp $ 5 6 Copyright 2002 (C) The Werken Company. All Rights Reserved. 7 8 Redistribution and use of this software and associated documentation 9 ("Software"), with or without modification, are permitted provided 10 that the following conditions are met: 11 12 1. Redistributions of source code must retain copyright 13 statements and notices. Redistributions must also contain a 14 copy of this document. 15 16 2. Redistributions in binary form must reproduce the 17 above copyright notice, this list of conditions and the 18 following disclaimer in the documentation and/or other 19 materials provided with the distribution. 20 21 3. The name "drools" must not be used to endorse or promote 22 products derived from this Software without prior written 23 permission of The Werken Company. For written permission, 24 please contact bob@werken.com. 25 26 4. Products derived from this Software may not be called "drools" 27 nor may "drools" appear in their names without prior written 28 permission of The Werken Company. "drools" is a registered 29 trademark of The Werken Company. 30 31 5. Due credit should be given to The Werken Company. 32 (http://drools.werken.com/). 33 34 THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS 35 ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 36 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 37 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 38 THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 39 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 40 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 41 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 42 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 43 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 44 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 45 OF THE POSSIBILITY OF SUCH DAMAGE. 46 */ 47 48 import java.io.*; 49 import java.util.ArrayList; 50 import java.util.List; 51 import java.util.Random; 52 53 /*** 54 * Miss Manners Data Generator 55 * 56 * The purpose of this program is to generate a file of make statements that can be used as 57 * an input data set for the Miss Manners OPS5c program. 58 * 59 * All input to this program will be interactively obtained from the user. 60 * The file of make statements will be written to file manners.dat. 61 * The user specifies how many guests there will be. Each guest's name will be a unique 62 * integer. Each guest is assigned a sex at random. 63 * The user can specify the total number of hobbies it is possible for a guest to have, 64 * and a lower limit of the number of hobbies for a guest. 65 * 66 * For instance, if the user chooses 10 hobbies and a lower limit of 3 hobbies, 67 * each guest will have between 3 and 10 hobbies. The hobbies will be designated with 68 * an integer. Finally, the user can specify the number of seats available. 69 * 70 * The sex of the guests is assigned so that approximately half of 71 * the guests are male and half are female. 72 * 73 * This is based on the work of Tim Grose. 74 * 75 * @author <a href="mailto:thomas.diesler@softcon-itec.de">thomas diesler</a> 76 */ 77 public class MannersDat { 78 79 private int numGuests = 64; 80 private int numSeats = 64; 81 private int minHobbies = 2; 82 private int maxHobbies = 3; 83 84 public static void main(String[] args) throws Exception { 85 MannersDat md = new MannersDat(); 86 md.initTestMetrics(); 87 md.generateData(); 88 } 89 90 /*** 91 * Generates the manners.dat file for the test metrics. 92 */ 93 private void generateData() throws IOException { 94 95 File file = new File("manners" + numGuests + ".dat"); 96 PrintWriter pw = new PrintWriter(new FileWriter(file)); 97 98 int maxMale = numGuests / 2; 99 int maxFemale = numGuests / 2; 100 101 int maleCount = 0; 102 int femaleCount = 0; 103 104 // init hobbies 105 List hobbyList = new ArrayList(); 106 for (int i = 1; i <= maxHobbies; i++) { 107 hobbyList.add("h" + i); 108 } 109 110 Random rnd = new Random(); 111 for (int i = 1; i <= numGuests; i++) { 112 113 char sex = rnd.nextBoolean() ? 'm' : 'f'; 114 if (sex == 'm' && maleCount == maxMale) sex = 'f'; 115 if (sex == 'f' && femaleCount == maxFemale) sex = 'm'; 116 if (sex == 'm') maleCount++; 117 if (sex == 'f') femaleCount++; 118 119 List guestHobbies = new ArrayList(hobbyList); 120 121 int numHobbies = minHobbies + rnd.nextInt(maxHobbies - minHobbies + 1); 122 for (int j = 0; j < numHobbies; j++) { 123 int hobbyIndex = rnd.nextInt(guestHobbies.size()); 124 String hobby = (String)guestHobbies.get(hobbyIndex); 125 pw.println("(guest (name n" + i + ") (sex " + sex + ") (hobby " + hobby + "))"); 126 guestHobbies.remove(hobbyIndex); 127 } 128 } 129 130 pw.println("(last_seat (seat " + numSeats + "))"); 131 132 pw.println(); 133 pw.println("(context (state start))"); 134 135 System.out.println("generated: " + file.getAbsoluteFile()); 136 137 pw.close(); 138 } 139 140 /*** 141 * Get the test metrics interactively 142 */ 143 private void initTestMetrics() throws IOException { 144 145 String instr = readInput("number of guests [64]: "); 146 if (instr.length() > 0) numGuests = new Integer(instr).intValue(); 147 148 instr = readInput("number of seats [64]: "); 149 if (instr.length() > 0) numSeats = new Integer(instr).intValue(); 150 151 instr = readInput("min hobbies [2]: "); 152 if (instr.length() > 0) minHobbies = new Integer(instr).intValue(); 153 154 instr = readInput("max hobbies [3]: "); 155 if (instr.length() > 0) maxHobbies = new Integer(instr).intValue(); 156 } 157 158 /*** 159 * Read a line of user input, for the given message. 160 */ 161 private String readInput(String msg) throws IOException { 162 System.out.print(msg); 163 BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 164 return br.readLine(); 165 } 166 }

This page was automatically generated by Maven