First attempt at including the installed packages in the version eq

The idea is to collect all packages of the same name into one variable
and add add its negation an additional term with one coefficient
higher than the highest version, i.e., so that removing a package is
possible, but is considered higher cost than any downgrade.
Move a variable definition down
Fix a bunch of little issues with the installed packages code

Make sure variable counts are correct. Get all versions of installed packages,
and use those everywhere.