1/* $Id: CoinWarmStartDual.cpp 1373 2011-01-03 23:57:44Z lou $ */
2// Copyright (C) 2003, International Business Machines
3// Corporation and others. All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
5
6#if defined(_MSC_VER)
7// Turn off compiler warning about long names
8# pragma warning(disable:4786)
9#endif
10
11#include <cassert>
12
13#include "CoinWarmStartDual.hpp"
14#include <cmath>
15
16//#############################################################################
17
18/*
19 Generate a `diff' that can convert the warm start passed as a parameter to
20 the warm start specified by this.
21
22 The capabilities are limited: the basis passed as a parameter can be no
23 larger than the basis pointed to by this.
24*/
25
26CoinWarmStartDiff*
27CoinWarmStartDual::generateDiff (const CoinWarmStart *const oldCWS) const
28{
29/*
30 Make sure the parameter is CoinWarmStartDual or derived class.
31*/
32 const CoinWarmStartDual *oldDual =
33 dynamic_cast<const CoinWarmStartDual *>(oldCWS) ;
34 if (!oldDual)
35 { throw CoinError("Old warm start not derived from CoinWarmStartDual.",
36 "generateDiff","CoinWarmStartDual") ; }
37
38 CoinWarmStartDualDiff* diff = new CoinWarmStartDualDiff;
39 CoinWarmStartDiff* vecdiff = dual_.generateDiff(&oldDual->dual_);
40 diff->diff_.swap(*dynamic_cast<CoinWarmStartVectorDiff<double>*>(vecdiff));
41 delete vecdiff;
42
43 return diff;
44}
45
46//=============================================================================
47/*
48 Apply diff to this warm start.
49
50 Update this warm start by applying diff. It's assumed that the
51 allocated capacity of the warm start is sufficiently large.
52*/
53
54void CoinWarmStartDual::applyDiff (const CoinWarmStartDiff *const cwsdDiff)
55{
56/*
57 Make sure we have a CoinWarmStartDualDiff
58*/
59 const CoinWarmStartDualDiff *diff =
60 dynamic_cast<const CoinWarmStartDualDiff *>(cwsdDiff) ;
61 if (!diff)
62 { throw CoinError("Diff not derived from CoinWarmStartDualDiff.",
63 "applyDiff","CoinWarmStartDual") ; }
64
65 dual_.applyDiff(&diff->diff_);
66}
67