ServiceFacilities Visualization
To aid in the development of your submission, we are providing a visualization
tool to competitors.
The tool is packaged as an executable jar, which can be run either by
double clicking it (in windows anyway) or from the command line as "java -jar
Service.jar".
As in previous contests, to use this visualization tool, you should create an application
that communicates with the tool via standard in and standard out. Note that
this does not effect the way your program should work when you submit it on
the TopCoder website.
The program that you write for the visualizer should start by reading the
parameters from standard input, one parameter per line. When reading integer
arrays, the entire array will be given on a single line, with integers separated
by spaces. The first integer on the line will N, the length of the array, which
will then be followed by N integers denoting the array. When writing your
result, you should write it in the same format as you read integer arrays (first
length, then contents).
For instance, to use the visualizer, you might implement the following
pseudocode, and adapt your solution to use it:
nextIntArray()
len = nextInt()
for(i = 0; i<len; i++)
ret[i] = nextInt()
return ret
main()
x = nextIntArray();
y = nextIntArray();
serviceImportance = nextIntArray();
serviceCost = nextIntArray();
budget = nextInt();
result = placeServices(x,y,serviceImportance,serviceCost,budget);
print(length(result))
for(i = 0; i<length(result); i++)
print(' ')
print(result[i])
print('\n')
flush(stdout)
Using the visualizer
To use the visualizer, you must have Java 1.5 or greater installed. To run
the visualizer, you can execute the command "java -jar Service.jar". This will
open up a new window containing the visualization, along with a number of
controls. The first thing you will need to do is specify the executable you
have made for your advertising code. You may either enter its path, or select it
via the button provided. If your executable requires arguments, enter them
in the provided field. For example, if your executable is a Java class
ServiceFacilities.class, you should enter something like "java ServiceFacilities" (without
the quotes) in this field (replacing "java" with the full path to the Java
executable if necessary). The exact details of what you enter here will
depend on your language choice. In particular, in Java, you will need to make
sure that the class file is in the same directory as Service.jar, or else you
will need to specify a classpath along with the executable location and class
name.
You may customize the game by entering any values for the parameters
that you like, and then clicking generate to make a test with those parameters. The
field seed is a seed for
the random number generator and will allow you to repeatedly generate
the same
test (note, however, that seed 0 means to use time as a seed). Clicking
the "Generate Map" button will generate the map based on your
parameters. Alternatively, you can select new random values for all
parameters by clicking "New Parameters". If you've changed the
seed,
since you last generated a map, the seed you entered will be used to
generate
the parameters as well as the map, otherwise a
new seed will be generated. To test the examples from the problem
statement,
you may simply enter the appropriate seeds and click "New Parameters".
When you run the simulation, any output you write to standard error,
along with messages from the visualization tool will appear. After your result
has been returned, you may change how you view it with the slider at top. This
controls which of the services is currently being focused on, while the shades
of grey in the display indicate the distance to the closest service of that
type.
Command Line Options
You can specify a number of parameters on the command line to
simplify the automation of testing (though you don't need to use any of them).
For example, "java -jar Service.jar -N 50" will set N to 5 when running the
tool.
-N <N> | |
-S <S> | |
-color <color> | Specify the service to focus on initially (set the slider at the top) |
-seed <seed> | Specify the initial seed |
-exec <command> | Specify the command to execute your code |
-novis | Run the test case without the visualizer (requires -exec, implies -go) |
-go | Start running immediately (requires -exec) |
-onewindow | Run in one window instead of 3 |
Final Notes
- Make sure you flush your buffers after writing to standard out, or the
visualization tool might not get your output, and it will appear to
hang.
-
Java users: if you get something java.lang.NoClassDefFoundError
ServiceFacilities,
it means that you've correctly set the path to Java, but Java can't find
your class. Among other things, you can try setting the command to something
like "PATH1\java -cp PATH2 ServiceFacilities", where PATH2 is the location of your
class file.
-
If the simulation fails to go, but there are no error messages, the most likely
explanation is that the visualization tool is still waiting for your program
to tell it what to do next. An obvious cause for this is that your program is
in some sort of an infinite loop. Another possible cause is that your program
is waiting for input which it will never get, as the visualization tool is
waiting for your program.
-
Please note that, while we will do our best to make the workings of the
visualizer as clear as possible, it
is impossible for us to help everyone debug their code to make it work with
the visualization tool. If you do think you have discovered a bug, please email
lbackstrom@topcoder.com or post the bug to the forums. The more details you
provide, the more likely you are to be helped quickly. Please to NOT post
code to the forums, as that is against the rules, and you will be disqualified.