예제 #1
0
        internal void ApplyWarmStart(OsiSolverInterface solver)
        {
            Ensure.NotNull(solver, "solver");

            unsafe
            {
                // set the primal solution
                if (numberColumns > 0)
                {
                    // if the new solver has *fewer* columns, then no problem.
                    // if the new solver has MORE columns, then make sure we dont copy wrong memory..
                    if (solver.getNumCols() > numberColumns)
                    {
                        int n = solver.getNumCols();

                        double[] newColSolution = new double[n];
                        fixed(double *newColSolutionPinned = newColSolution)
                        {
                            // copy the first NumberOfColumns into the new array
                            CoinUtils.CoinDisjointCopyN(colSolution, numberColumns, newColSolutionPinned);
                            // then fill it up with zeros
                            CoinUtils.CoinZeroN(&newColSolutionPinned[numberColumns], (n - numberColumns));
                        }

                        solver.setColSolution(newColSolution);
                    }
                    else
                    {
                        solver.setColSolutionUnsafe(colSolution);
                    }

                    // set the dual solution
                    if (numberRows > 0)
                    {
                        // if the new solver has *fewer* rows, then no problem.
                        // if the new solver has MORE rows, then make sure we dont copy wrong memory..
                        if (solver.getNumRows() > numberRows)
                        {
                            int m = solver.getNumRows();

                            double[] newRowPrice = new double[m];
                            fixed(double *newRowPricePinned = newRowPrice)
                            {
                                // copy the first NumberOfRows into the new array
                                CoinUtils.CoinDisjointCopyN(rowPrice, numberRows, newRowPricePinned);
                                // then fill it up with zeros
                                CoinUtils.CoinZeroN(&newRowPricePinned[numberRows], (m - numberRows));
                            }

                            solver.setRowPrice(newRowPrice);
                        }
                        else
                        {
                            solver.setRowPriceUnsafe(rowPrice);
                        }
                    }
                }
#if (!SONNET_SETWARMROWPRICE)
                if (numberRows > 0 || rowPrice != null)
                {
                    throw new NotSupportedException();
                }
#endif
            }

            // set the warmstart object
            solver.setWarmStart(coinWarmStart);
        }