Machine Problem 2, due Feb 22

Part of the homework for CS:2820, Fall 2015
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Write a Java program, in file NeuronNetwork.java that can be run as follows to read data from a file called f (presuming that this file exists):

[HawkID@serv15 project]$ java NeuronNetwork f

When your program is run, it should read a description of a network of neurons, here is an example description (based on the file format documented in Homework 4 problem 2):

neuron A 1.0 0.95
neuron B 1.0 0.0
synapse A B 1.2  0.5
synapse B A 0.3 -0.5

For synapses, the first number is the delay, the second number is the strength. written in the notation of Homework 3 Problem 3 part c, and built a data structure of objects using the basic object classes documented in the posted solution to Homework 3 Problem 3d, with one added detail: Neurons have textual names.

Having created this data structure, the program should print out a description of the circuit it created, in exactly the same notation as is used in the input file, but to the standard output stream.

Error messages: Your program should report any errors it detects: If it can't open the input file, lines that don't start with neuron or synapse, missing fields on a line, negative time delays, synapses that reference non-existant neurons, etc. Your error messages should be helpful, but need not be elaborate. Consider this input file:

neuron A 1.000 0.950
neuron B 0.7 word
synapse A C 1.2 0.5
  synapse  A  B  -3  1.0
neuron A 0.7 1.3

Your program might report the following error messages as a result of trying to read the above file:

Error: neuron B, number expected, found word
Error: wire A C, no neuron C
Error: wire A B, negative delay -3.0
Error: neuron A, redefinition

The details of the error messages given above are just suggestions, but each of them points out a genuine error in the input file. In order to prevent cascading error messages, errors in numeric fields should be replaced with the default value 99.99 (if you simply ignored the lines containing errors, an error in a neuron definition would cause all of the synapses connected to that neuron to be flagged as errors). Duplicate definitions and wire definitioins containing errors can be ignored.

Output: After reporting any errors, your program should traverse the data structures it has built to produce an output file describing the neuron network. This file should conform to the same rules as the input file. For example, after reading the input file given above, it might output the following:

neuron A 1.0 0.95
neuron B 0.7 99.99

Note that the default behavior of the scanner was to skip as many blanks as needed to get to the next item, but the output only put one blank. Note that the output prints floating-point values in a standard compact form, without excessive leading or trailing zeros that might have been used in the input.

Grading criteria: No credit will be given to programs that do not represent a substantial attempt at meeting the requirements of this assignment. Your program must:

Note that the requirements for header comments in the file header are absolute. Your name must appear in the form that it appears on your ID card. The TAs will not waste their time doing detective work to attempt to figure out who submitted what code.

Submission: Your solution should consist of a single file, with one public method, main. (Later, we will chop the file into smaller more managable pieces, as it grows.)

To submit your solution, make sure it is in a file called NeuronNetwork.java (this requires that the main method be in a class called NeuronNetwork. This must be in the current directory. Then, follow the following dialogue with the Linux shell (what you type is given in boldface):

[HawkID@serv16 ~/project]$ submit NeuronNetwork.java
Course (22C:016 would be c_016): CS2820
Possible submit directories for /group/submit/CS2820 are:

The dialogue continues as in MP1, except that the submit directory for this assignment will be named mp2 instead of mp1