SolutionGuarantor: store costs before solving

Store segment costs before running the solver. While this is slightly
messy in that it moves one of the SegmentStore operations out of
guaranteeSolution, it has two performance benefits. First, since
PostgreSQL stores are asynchronous it allows the store query to be
quickly sent, and the execution within the database to overlap the
solver locally. Previously it was executed just before solution storing,
which meant storeSolution had to wait for the cost query to finish before
executing. Second, by storing costs earlier it allows concurrent
SolutionGuarantors accessing some of these segments to avoid recomputing
those costs if readCosts is enabled.