# Command Line Solvers

For most methods, Cain uses command line executables to carry out the simulations. The executables are in the `solvers` directory.

It is easy to add a new simulation method to Cain if it is similar to one of the built-in methods. Just write a program that reads the same input format and generates the same output format as one of the other solvers. You can write your program in any language and use any software or hardware resources that you have on your machine. Place your program in the `solvers` directory. Then edit the data in the file `state/simulationMethods.py`. Note that the Cain solvers are serial. The application utilizes concurrency by running multiple instances of a solver. If your solver has multiple threads, then you should select one process in the launcher panel when using your solver, so that only one instance of the solver is run.

If you would like to add a solver to the Cain distribution, contact me at . Your work will be noted in the Simulation Methods chapter of this documentation. I will add links to any of your relevant papers and web sites. The contributed code will be distributed under the three-clause BSD license.

While there is great flexibility in developing personal extensions to Cain, contributed solvers should roughly match the built-in solvers. The best way to proceed is to use an existing solver as a template. You will want to use the random number package in `src/numerical/random`. The solvers take an initial state of the Mersenne Twister as input and return the final state. Note that most of the built-in solvers can either be used with mass action kinetics or custom propensities (i.e. the propensity functions for the reactions may be any user-defined function). To accomplish this, the C++ solver classes take the propensities functor as a template parameter. For mass action kinetics, the propensity functor will be either `PropensitiesSingle` or `PropensitiesAll`, which are defined in `src/stochastic/Propensities.h`. For custom propensities, the propensity functor is the `Propensities` class, defined in `src/solvers/Propensities.h`. When a solver with custom propensities is run, the application generates appropriate C++ code, compiles the solver, and then launches it. When writing your solver, it may be easier to initially support only mass-action kinetics. Once that is working, you may add the custom propensities capability.

When developing your solver, you can either put it in the `src/solvers` directory and use the makefile there to compile it, or you may place it in an arbitrary directory. If you choose the latter option. Copy the contents of `src` to a convenient location and add it to your include path. Note that all of the packages in `src` are template class libraries. That is, they are just header files. To use a package, simply include the appropriate header. There is no need to compile any libraries and link with them.