Guest User

Untitled

a guest
Sep 5th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.05 KB | None | 0 0
  1. Java program hangs at Window shell
  2. C:quadrantRDBTemplate>java -cp iucbrf.jar;mysql-connector-java-5.0.jar edu.indi
  3. ana.iucbrf.examples.quadrantRDBTemplate.QuadrantTestClassRDB > log.txt
  4. Exception in thread "Thread-3" java.lang.RuntimeException: java.lang.RuntimeExce
  5. ption: java.io.EOFException
  6. at edu.indiana.util.Base64Tools.decode(Base64Tools.java:58)
  7. at edu.indiana.iucbrf.feature.featurespec.FeatureSpecRDB.setAllFeatureSp
  8. ecShellsIntoCache(FeatureSpecRDB.java:238)
  9. at edu.indiana.iucbrf.feature.featurespec.FeatureSpecRDB.readFeatureSpec
  10. RDBIntoCache(FeatureSpecRDB.java:201)
  11. at edu.indiana.iucbrf.feature.featurespec.FeatureSpecRDB.doThreadedOpera
  12. tion(FeatureSpecRDB.java:189)
  13. at edu.indiana.util.multithreaded.DBLoaderThread.run(DBLoaderThread.java
  14. :57)
  15. at java.lang.Thread.run(Unknown Source)
  16.  
  17. package edu.indiana.iucbrf.examples.quadrantRDBTemplate;
  18.  
  19. import edu.indiana.iucbrf.feature.FeatureKey;
  20. import edu.indiana.iucbrf.maintenance.NullMaintenance;
  21. import edu.indiana.iucbrf.retrieval.Retrieval;
  22. import edu.indiana.iucbrf.retrieval.kNN;
  23. import edu.indiana.iucbrf.adaptation.DistanceWeightedAdapter;
  24. import edu.indiana.iucbrf.performancemonitor.PerformanceMonitor;
  25. import edu.indiana.iucbrf.problem.ProblemGenerator;
  26. import edu.indiana.iucbrf.casepackage.CaseGenerator;
  27. import edu.indiana.iucbrf.casebase.FlatCaseBase;
  28. import edu.indiana.iucbrf.cbrsystem.CBRSystem;
  29. import edu.indiana.util.distribution.UniformDistribution;
  30. import java.util.HashMap;
  31. import java.sql.Driver;
  32.  
  33. import java.sql.DriverManager;
  34. import java.sql.Connection;
  35. import java.sql.SQLException;
  36. import java.util.Map;
  37.  
  38. import edu.indiana.iucbrf.casebase.RDBCaseBase;
  39. import edu.indiana.iucbrf.feature.featurespec.FeatureSpecCollection;
  40. import edu.indiana.iucbrf.feature.FeatureCollection;
  41. import edu.indiana.iucbrf.feature.featurespec.FeatureSpecRDBInfo;
  42. import edu.indiana.util.db.JDBCDriverInfo;
  43. import edu.indiana.iucbrf.casebase.RDBCaseBaseInfo;
  44. import edu.indiana.iucbrf.domain.DBInfo;
  45.  
  46.  
  47.  
  48. public class QuadrantSystemRDB
  49. extends CBRSystem {
  50.  
  51. ///////////////////////////////////////////////////////////////////////////
  52. // Database configuration
  53. public static final String USERNAME;
  54. public static final String PASSWORD;
  55. //public static final String HOST_NAME;
  56. //public static final String SERVICE_NAME;
  57.  
  58. /* Set the above variables appropriately for your database configuration. Additional
  59. * code modifications may also be necessary depending on your configuration.
  60. */
  61. static {
  62. //if (true)
  63. // throw new UnsupportedOperationException("nn*************** NOTICE ***************nThis exception is expected! You must set a few constants in QuadrantSystemRDB, according to your database configuration, and then comment out this exception.");
  64. USERNAME = "root";
  65. PASSWORD = "123456";
  66. // HOST_NAME = "localhost";
  67. // SERVICE_NAME = "";
  68. }
  69. ///////////////////////////////////////////////////////////////////////////
  70.  
  71. /** The number of cases to be in the case base. Of course, performance of
  72. * the system depends on how many cases are available.
  73. */
  74. private static final int NUM_CASES = 5;
  75.  
  76. /** The keys to the two problem features. */
  77. private FeatureKey xKey;
  78. private FeatureKey yKey;
  79. DBInfo dbInfo;
  80. FeatureSpecRDBInfo problemSpecInfo;
  81. FeatureSpecRDBInfo solutionSpecInfo;
  82. RDBCaseBaseInfo rdbCasebaseInfo;
  83.  
  84. /** Creates a new instance of QuadrantSystem */
  85. public QuadrantSystemRDB() {
  86.  
  87. //Defines the required info classes
  88. //setupInfo();
  89. try {
  90. setupInfo();
  91. }
  92. catch (java.sql.SQLException e) {
  93. // you may want to do something useful here
  94. // maybe even throw new RuntimException();
  95. }
  96.  
  97.  
  98. // Define the domain, which describes the type of problems the system will solve.
  99. setupDomain();
  100.  
  101. // Create the case base and add cases to it.
  102. setupCaseBase();
  103.  
  104. // Do no maintenance for this system
  105. setMaintenance(new NullMaintenance());
  106.  
  107. // Retrieval will be 5-nearest neighbor
  108. Retrieval retrieval = new kNN(getDomain().getProblemDifferentiator(), 5);
  109. setRetrieval(retrieval);
  110.  
  111. // The adaptation technique is a distance-weighted majority vote.
  112. setAdaptation(new DistanceWeightedAdapter("edu.indiana.iucbrf.adaptation.WeightedMajorityAdapter"));
  113.  
  114. // Track the system performance with the performance monitor
  115. setPerformanceMonitor(new PerformanceMonitor());
  116. }
  117.  
  118. private void setupInfo() throws SQLException
  119. {
  120. Driver driver = new com.mysql.jdbc.Driver();
  121.  
  122. String url = "jdbc:mysql://localhost:3306/hpdata";
  123. String username = USERNAME;
  124. String password = PASSWORD;
  125. String problemFeatureSpecTableName = "ProblemFeatureSpec";
  126. String solutionFeatureSpectTableName = "SolutionFeatureSpec";
  127. String classTableName = "Class";
  128. String extraDataTableName = "ExtraData";
  129. String casebaseTablename = "CaseBase";
  130. String problemTableName = "Problem";
  131. String solutionTableName = "Solution";
  132. String inactiveContextsTableName = "InactiveContext";
  133. String constantsTableName = "Constants";
  134. dbInfo = new DBInfo(new JDBCDriverInfo(driver, url, username, password),constantsTableName);
  135. problemSpecInfo = new FeatureSpecRDBInfo(problemFeatureSpecTableName, classTableName, extraDataTableName);
  136. solutionSpecInfo = new FeatureSpecRDBInfo(solutionFeatureSpectTableName, classTableName, extraDataTableName);
  137. rdbCasebaseInfo = new RDBCaseBaseInfo(casebaseTablename, solutionTableName, problemTableName, inactiveContextsTableName);
  138. }
  139.  
  140.  
  141. // Define the domain, which describes the type of problems the system will solve.
  142. private void setupDomain() {
  143. QuadrantDomainRDB domain = new QuadrantDomainRDB(dbInfo, problemSpecInfo, solutionSpecInfo);
  144.  
  145. /* Add the two problem features: x and y. The textual description,
  146. * type, and similarity weight are specified. The return values are keys
  147. * that will be referred to in additional setup steps.
  148. */
  149.  
  150. long start, end, totalTime;
  151. start = System.currentTimeMillis();
  152. xKey = domain.addProblemFeature("x", "edu.indiana.iucbrf.feature.DoubleFeature", 1, true);
  153. end = System.currentTimeMillis();
  154. totalTime = end - start;
  155. System.out.println("Total Time to add a featurespec: " + totalTime + " in millisec");
  156.  
  157.  
  158. FeatureSpecCollection fsc = domain.getFeatureSpecCollection(FeatureCollection.PROBLEM_FEATURE_COLLECTION);
  159. start = System.currentTimeMillis();
  160. fsc.getFeatureSpec(xKey);
  161. end = System.currentTimeMillis();
  162. totalTime = end - start;
  163. System.out.println("Total Time to get a featurespec: " + totalTime + " in millisec");
  164.  
  165. yKey = domain.addProblemFeature("y", "edu.indiana.iucbrf.feature.DoubleFeature", 1, true);
  166.  
  167. /* Add the solution feature: quadrant. A key is assigned, but it is not
  168. * needed at this time.
  169. */
  170.  
  171. domain.addSolutionFeature("Quadrant", "edu.indiana.iucbrf.feature.IntegerFeature");
  172.  
  173. /* The reference solution for this domain requires the xKey and yKey. See
  174. introductory paper for details on reference methods. */
  175.  
  176. domain.prepareReferenceSolution(xKey, yKey);
  177.  
  178. setDomain(domain);
  179.  
  180. }
  181.  
  182. /** The case base must be populated. For this example, random generation is
  183. * possible and sufficient.
  184. */
  185. private void setupCaseBase() {
  186.  
  187. // The case generator can be built from the problem generator.
  188. CaseGenerator cg = new CaseGenerator(constructProblemGenerator(), getDomain());
  189.  
  190. /** Construct the case base, with a simple flat structure. For this
  191. * constructor, the case generator and the desired number of initial cases
  192. * can be passed.
  193. */
  194. long start;
  195. long end;
  196. long totalTime;
  197. start = System.currentTimeMillis();
  198. setCB(new RDBCaseBase(getDomain(), rdbCasebaseInfo, cg, NUM_CASES));
  199. end = System.currentTimeMillis();
  200. totalTime = end - start;
  201. System.out.println("Total Time to setup casebase with " + NUM_CASES + " : " + totalTime + " in millisec");
  202. }
  203.  
  204. /** A problem generator requires specification of arguments to send to
  205. * feature constructors. Here, random distributions are used.
  206. */
  207.  
  208.  
  209. public ProblemGenerator constructProblemGenerator() {
  210. HashMap argMap = new HashMap(2);
  211. argMap.put(xKey, new UniformDistribution(-1, 1));
  212. argMap.put(yKey, new UniformDistribution(-1, 1));
  213.  
  214. return new ProblemGenerator(argMap, getDomain());
  215. }
  216. }
  217.  
  218. package edu.indiana.iucbrf.examples.quadrantRDBTemplate;
  219.  
  220. import edu.indiana.iucbrf.problem.Problem;
  221. import java.sql.Driver;
  222. import java.io.IOException;
  223. import java.sql.DriverManager;
  224. import java.sql.Connection;
  225. import java.sql.Statement;
  226.  
  227. /**
  228. * This class contains a simple main method that constructs a QuadrantSystemRDB
  229. * and tests it on a single problem. This demonstrates basic database functionality.
  230. * In order to run this program, you will need to configure your database
  231. * (edu/creation_script.sql may be helpful in this task) and perhaps
  232. * modify the settings here accordingly. You will also need to set some parameters as
  233. * discussed in QuadrantSystemRDB.
  234. *
  235. * @author Steven Bogaerts
  236. */
  237. public class QuadrantTestClassRDB {
  238.  
  239. /** Constructs the system, and tests it on a single problem. */
  240. public static void main(String[] args) {
  241. System.out.println("Hello World! ...... ");
  242. flush();
  243.  
  244. long start, end, totalTime;
  245.  
  246. // Construct the system.
  247. start = System.currentTimeMillis();
  248.  
  249. QuadrantSystemRDB sys = new QuadrantSystemRDB();
  250. end = System.currentTimeMillis();
  251. totalTime = end - start;
  252. System.out.println("Total Time to construct system: " + totalTime + " in millisec");
  253.  
  254. // Set the system to show a GUI of its status.
  255. sys.setGUIMode(true);
  256.  
  257. /* Generate a problem to test the system on. This problem generator is
  258. defined in the QuadrantSystem class. */
  259. start = System.currentTimeMillis();
  260.  
  261. Problem p = sys.constructProblemGenerator().generateProblem();
  262. end = System.currentTimeMillis();
  263. totalTime = end - start;
  264. System.out.println("Total Time to generate a problem: " + totalTime + " in millisec");
  265.  
  266. // Solve the problem. The GUI will show what happens.
  267. start = System.currentTimeMillis();
  268. sys.solve(p);
  269. sys.close();
  270. end = System.currentTimeMillis();
  271. totalTime = end - start;
  272. System.out.println("Total Time to solve a problem: " + totalTime + " in millisec");
  273. }
  274.  
  275. private static void flush() {
  276. String url = "jdbc:mysql://localhost:3306/hpdata";
  277. Connection con;
  278. Statement stmt;
  279. String query1 = "Delete from casebase";
  280. String query2 = "Delete from problem";
  281. String query3 = "Delete from solution";
  282. String query4 = "Delete from problemfeaturespec";
  283. String query5 = "Delete from solutionfeaturespec";
  284. String query6 = "Delete from inactivecontext";
  285. String query7 = "Delete from class";
  286. String query8 = "Delete from extradata";
  287.  
  288. try {
  289. DriverManager.registerDriver(new com.mysql.jdbc.Driver());
  290. // DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
  291. } catch (Exception e) {
  292. System.out.println("Class Not Found Exception:");
  293. System.out.println(e.getMessage());
  294. }
  295.  
  296.  
  297.  
  298.  
  299. try {
  300. con = DriverManager.getConnection(url, QuadrantSystemRDB.USERNAME, QuadrantSystemRDB.PASSWORD);
  301. stmt = con.createStatement();
  302. System.out.println("Deleting Tables from Database...");
  303. System.out.println("casebase...");
  304. stmt.executeUpdate(query1);
  305. System.out.println("deletedn");
  306. System.out.println("problem...");
  307. stmt.executeUpdate(query2);
  308. System.out.println("deletedn");
  309. System.out.println("solution...");
  310. stmt.executeUpdate(query3);
  311. System.out.println("deletedn");
  312. System.out.println("problemfeaturespec...");
  313. stmt.executeUpdate(query4);
  314. System.out.println("deletedn");
  315. System.out.println("solutionfeaturespec...");
  316. stmt.executeUpdate(query5);
  317. System.out.println("deletedn");
  318. System.out.println("inactivecontext...");
  319. stmt.executeUpdate(query6);
  320. System.out.println("deletedn");
  321. System.out.println("class...");
  322. stmt.executeUpdate(query7);
  323. System.out.println("deletedn");
  324. System.out.println("extradata...");
  325. stmt.executeUpdate(query8);
  326. System.out.println("deletedn");
  327. stmt.close();
  328. con.close();
  329. } catch (Exception e) {
  330. System.out.println("SQLException:" + e.getMessage());
  331. e.printStackTrace();
  332. }
  333. }
  334. }
Add Comment
Please, Sign In to add comment