Quick Start
Setting up and running the demo
The code was built and delivered as a Visual Studio 2015 solution. It comes with a demo
to illustrate basic capabilities of the library and tool. If you are
already familiar with Visual Studio, you can go directly to step 4 to run the demo.
If you do not have Visual Studio, download the
free Visual Studio Community Edition and follow the
instruction to install the software. Once the installation is complete:
-
Clone or download the Algs4Net
solution and change to the directory where the Algs4Net.sln file is.
-
Use Visual Studio to open Algs4net.sln. After the solution is loaded, within the Solution Explorer
window, there are three projects:
-
Algs4Net is the core library of the solution
-
Algs4NetTests contains sample unit tests for selected classes from Algs4Net
-
AlgsCmd is the command-line tool to call MainTest’s methods of Algs4Net classes.
-
In Solution Explorer, make sure that AlgsCmd is the StartUp project by right
clicking the project and select the "Set as StartUp project" option in the pop-up
menu. Then AlgsCmd should be in bold, meaning that it is now the
StartUp project.
-
Also, right click the project and select the "Properties" option to open
the project properties in the main Visual Studio window:
-
Examine the properties to suite your needs. Particularly note the working
directory of the program. It is where you may later put data files as needed.
-
Note that in the Debug → Start Options section, there is
a text box for command line arguments. Enter
Animation
to run the demo.
-
In Visual Studio, select Build → Build Solution or press
Ctrl-Shift-B to build all the projects.
-
After the build is complete, select Debug → Start Debugging
(or Start Without Debugging) to run the program.
-
A window should come up and ready to run the demo. Switch to the new window,
click the Start button to start the animation, Stop to stop it. Optionally,
select the File menu to save the display in a file.
-
Exit the demo window. Even though the demo has illustrated the library's
basic drawing capabilities, most of the times you will be using algscmd with
the console for your algorithms. As you may already know, the console can be
accessed from the IDE or command line.
-
To run the demo from a command line, open the command line window and change
directory to
[path-to-algs4net]\Algs4Net\AlgsCmd\bin\Debug
(or Release
)
and enter the command: algscmd Animation
. The demo window
should pop up from the command line window.
How to add new classes to Algs4Net
You may have already figured out how. This instruction is provided for completeness:
- Add a new class to the Algs4Net project from Visual Studio.
- Write the core code for the class.
- Add the
public static void MainTest(string[] args)
method to the class.
- Write the test code for the method.
- The MainTest method is your demo test to run with algscmd. Know which arguments
you may need for the test and parse them from the args array, starting at index 0
as if you would from a console program's Main entry.
- When you are ready to run the test, open the AlgsCmd project properties and enter in
the text box the name of your class followed by your arguments in parsing order.
- If you want to add drawing capabilities, follow the example in the Animation class.
What’s next
After the setup, follow these tips to test and develop your own algorithms using the library:
-
The working directory in step 4.a would be best the same as the command line directory
where you find and run algscmd.exe, either from the Debug or Release directory.
-
The data files for use with
the library can be downloaded and put in the working directory.
-
The first argument to algscmd is the class name you want to run its demo test (MainTest).
Consult the class’s header comment or the HelpText attribute of the class’s MainTest
method to see which argument(s) to use.
-
The algscmd tool has a simple help facility. Enter
algscmd
alone,
algscmd list
, or aglscmd h class_name
for a help topic.
-
Alternative to MainTest methods are the unit test programs in the Algs4NetTests test project.
If you are not familiar with the Microsoft's unit test framework, consult the
Unit Test Basics
page and then add unit tests to the Algs4NetTests project for your algorithms.
Since the library is intended use with the Algorithms, 4th Edition
textbook, the text’s web site is the main resource for everything else. There is much to improve to the
library and you are welcome to change it to suite your needs. Also, please do not hesitate to report
issues as we are committed to provide follow-on support for the library and will welcome any feedback.