source: stable/2.5/Cbc/src/CbcLinked.hpp @ 1510

Last change on this file since 1510 was 1432, checked in by bjarni, 10 years ago

Added extra return at end of each source file where needed, to remove possible linefeed conflicts (NightlyBuild? errors)

File size: 40.9 KB
Line 
1/* $Id: CbcLinked.hpp 1200 2009-07-25 08:44:13Z forrest $ */
2// Copyright (C) 2006, International Business Machines
3// Corporation and others.  All Rights Reserved.
4#ifndef CglLinked_H
5#define CglLinked_H
6/* THIS CONTAINS STUFF THAT SHOULD BE IN
7   OsiSolverLink
8   OsiBranchLink
9   CglTemporary
10*/
11#include "CoinModel.hpp"
12#include "OsiClpSolverInterface.hpp"
13#include "OsiChooseVariable.hpp"
14#include "CbcFathom.hpp"
15class CbcModel;
16class CoinPackedMatrix;
17class OsiLinkedBound;
18class OsiObject;
19class CglStored;
20class CglTemporary;
21/**
22
23This is to allow the user to replace initialSolve and resolve
24This version changes coefficients
25*/
26
27class OsiSolverLink : public CbcOsiSolver {
28
29public:
30    //---------------------------------------------------------------------------
31    /**@name Solve methods */
32    //@{
33    /// Solve initial LP relaxation
34    virtual void initialSolve();
35
36    /// Resolve an LP relaxation after problem modification
37    virtual void resolve();
38
39    /**
40       Problem specific
41       Returns -1 if node fathomed and no solution
42                0 if did nothing
43            1 if node fathomed and solution
44       allFixed is true if all LinkedBound variables are fixed
45    */
46    virtual int fathom(bool allFixed) ;
47    /** Solves nonlinear problem from CoinModel using SLP - may be used as crash
48        for other algorithms when number of iterations small.
49        Also exits if all problematical variables are changing
50        less than deltaTolerance
51        Returns solution array
52    */
53    double * nonlinearSLP(int numberPasses, double deltaTolerance);
54    /** Solve linearized quadratic objective branch and bound.
55        Return cutoff and OA cut
56    */
57    double linearizedBAB(CglStored * cut) ;
58    /** Solves nonlinear problem from CoinModel using SLP - and then tries to get
59        heuristic solution
60        Returns solution array
61        mode -
62        0 just get continuous
63        1 round and try normal bab
64        2 use defaultBound_ to bound integer variables near current solution
65    */
66    double * heuristicSolution(int numberPasses, double deltaTolerance, int mode);
67
68    /// Do OA cuts
69    int doAOCuts(CglTemporary * cutGen, const double * solution, const double * solution2);
70    //@}
71
72
73    /**@name Constructors and destructors */
74    //@{
75    /// Default Constructor
76    OsiSolverLink ();
77
78    /** This creates from a coinModel object
79
80        if errors.then number of sets is -1
81
82        This creates linked ordered sets information.  It assumes -
83
84        for product terms syntax is yy*f(zz)
85        also just f(zz) is allowed
86        and even a constant
87
88        modelObject not const as may be changed as part of process.
89    */
90    OsiSolverLink(  CoinModel & modelObject);
91    // Other way with existing object
92    void load(  CoinModel & modelObject, bool tightenBounds = false, int logLevel = 1);
93    /// Clone
94    virtual OsiSolverInterface * clone(bool copyData = true) const;
95
96    /// Copy constructor
97    OsiSolverLink (const OsiSolverLink &);
98
99    /// Assignment operator
100    OsiSolverLink & operator=(const OsiSolverLink& rhs);
101
102    /// Destructor
103    virtual ~OsiSolverLink ();
104
105    //@}
106
107
108    /**@name Sets and Gets */
109    //@{
110    /// Add a bound modifier
111    void addBoundModifier(bool upperBoundAffected, bool useUpperBound, int whichVariable, int whichVariableAffected,
112                          double multiplier = 1.0);
113    /// Update coefficients - returns number updated if in updating mode
114    int updateCoefficients(ClpSimplex * solver, CoinPackedMatrix * matrix);
115    /// Analyze constraints to see which are convex (quadratic)
116    void analyzeObjects();
117    /// Add reformulated bilinear constraints
118    void addTighterConstraints();
119    /// Objective value of best solution found internally
120    inline double bestObjectiveValue() const {
121        return bestObjectiveValue_;
122    }
123    /// Set objective value of best solution found internally
124    inline void setBestObjectiveValue(double value) {
125        bestObjectiveValue_ = value;
126    }
127    /// Best solution found internally
128    inline const double * bestSolution() const {
129        return bestSolution_;
130    }
131    /// Set best solution found internally
132    void setBestSolution(const double * solution, int numberColumns);
133    /// Set special options
134    inline void setSpecialOptions2(int value) {
135        specialOptions2_ = value;
136    }
137    /// Say convex (should work it out) - if convex false then strictly concave
138    void sayConvex(bool convex);
139    /// Get special options
140    inline int specialOptions2() const {
141        return specialOptions2_;
142    }
143    /** Clean copy of matrix
144        So we can add rows
145    */
146    CoinPackedMatrix * cleanMatrix() const {
147        return matrix_;
148    }
149    /** Row copy of matrix
150        Just genuine columns and rows
151        Linear part
152    */
153    CoinPackedMatrix * originalRowCopy() const {
154        return originalRowCopy_;
155    }
156    /// Copy of quadratic model if one
157    ClpSimplex * quadraticModel() const {
158        return quadraticModel_;
159    }
160    /// Gets correct form for a quadratic row - user to delete
161    CoinPackedMatrix * quadraticRow(int rowNumber, double * linear) const;
162    /// Default meshSize
163    inline double defaultMeshSize() const {
164        return defaultMeshSize_;
165    }
166    inline void setDefaultMeshSize(double value) {
167        defaultMeshSize_ = value;
168    }
169    /// Default maximumbound
170    inline double defaultBound() const {
171        return defaultBound_;
172    }
173    inline void setDefaultBound(double value) {
174        defaultBound_ = value;
175    }
176    /// Set integer priority
177    inline void setIntegerPriority(int value) {
178        integerPriority_ = value;
179    }
180    /// Get integer priority
181    inline int integerPriority() const {
182        return integerPriority_;
183    }
184    /// Objective transfer variable if one
185    inline int objectiveVariable() const {
186        return objectiveVariable_;
187    }
188    /// Set biLinear priority
189    inline void setBiLinearPriority(int value) {
190        biLinearPriority_ = value;
191    }
192    /// Get biLinear priority
193    inline int biLinearPriority() const {
194        return biLinearPriority_;
195    }
196    /// Return CoinModel
197    inline const CoinModel * coinModel() const {
198        return &coinModel_;
199    }
200    /// Set all biLinear priorities on x-x variables
201    void setBiLinearPriorities(int value, double meshSize = 1.0);
202    /** Set options and priority on all or some biLinear variables
203        1 - on I-I
204        2 - on I-x
205        4 - on x-x
206        or combinations.
207        -1 means leave (for priority value and strategy value)
208    */
209    void setBranchingStrategyOnVariables(int strategyValue, int priorityValue = -1,
210                                         int mode = 7);
211    /// Set all mesh sizes on x-x variables
212    void setMeshSizes(double value);
213    /** Two tier integer problem where when set of variables with priority
214        less than this are fixed the problem becomes an easier integer problem
215    */
216    void setFixedPriority(int priorityValue);
217    //@}
218
219    //---------------------------------------------------------------------------
220
221protected:
222
223
224    /**@name functions */
225    //@{
226    /// Do real work of initialize
227    //void initialize(ClpSimplex * & solver, OsiObject ** & object) const;
228    /// Do real work of delete
229    void gutsOfDestructor(bool justNullify = false);
230    /// Do real work of copy
231    void gutsOfCopy(const OsiSolverLink & rhs) ;
232    //@}
233
234    /**@name Private member data */
235    //@{
236    /** Clean copy of matrix
237        Marked coefficients will be multiplied by L or U
238    */
239    CoinPackedMatrix * matrix_;
240    /** Row copy of matrix
241        Just genuine columns and rows
242    */
243    CoinPackedMatrix * originalRowCopy_;
244    /// Copy of quadratic model if one
245    ClpSimplex * quadraticModel_;
246    /// Number of rows with nonLinearities
247    int numberNonLinearRows_;
248    /// Starts of lists
249    int * startNonLinear_;
250    /// Row number for a list
251    int * rowNonLinear_;
252    /** Indicator whether is convex, concave or neither
253        -1 concave, 0 neither, +1 convex
254    */
255    int * convex_;
256    /// Indices in a list/row
257    int * whichNonLinear_;
258    /// Model in CoinModel format
259    CoinModel coinModel_;
260    /// Number of variables in tightening phase
261    int numberVariables_;
262    /// Information
263    OsiLinkedBound * info_;
264    /**
265       0 bit (1) - call fathom (may do mini B&B)
266       1 bit (2) - quadratic only in objective (add OA cuts)
267       2 bit (4) - convex
268       3 bit (8) - try adding OA cuts
269       4 bit (16) - add linearized constraints
270    */
271    int specialOptions2_;
272    /// Objective transfer row if one
273    int objectiveRow_;
274    /// Objective transfer variable if one
275    int objectiveVariable_;
276    /// Objective value of best solution found internally
277    double bestObjectiveValue_;
278    /// Default mesh
279    double defaultMeshSize_;
280    /// Default maximum bound
281    double defaultBound_;
282    /// Best solution found internally
283    double * bestSolution_;
284    /// Priority for integers
285    int integerPriority_;
286    /// Priority for bilinear
287    int biLinearPriority_;
288    /// Number of variables which when fixed help
289    int numberFix_;
290    /// list of fixed variables
291    int * fixVariables_;
292    //@}
293};
294/**
295   List of bounds which depend on other bounds
296*/
297
298class OsiLinkedBound {
299
300public:
301    //---------------------------------------------------------------------------
302    /**@name Action methods */
303    //@{
304    /// Update other bounds
305    void updateBounds(ClpSimplex * solver);
306    //@}
307
308
309    /**@name Constructors and destructors */
310    //@{
311    /// Default Constructor
312    OsiLinkedBound ();
313    /// Useful Constructor
314    OsiLinkedBound(OsiSolverInterface * model, int variable,
315                   int numberAffected, const int * positionL,
316                   const int * positionU, const double * multiplier);
317
318    /// Copy constructor
319    OsiLinkedBound (const OsiLinkedBound &);
320
321    /// Assignment operator
322    OsiLinkedBound & operator=(const OsiLinkedBound& rhs);
323
324    /// Destructor
325    ~OsiLinkedBound ();
326
327    //@}
328
329    /**@name Sets and Gets */
330    //@{
331    /// Get variable
332    inline int variable() const {
333        return variable_;
334    }
335    /// Add a bound modifier
336    void addBoundModifier(bool upperBoundAffected, bool useUpperBound, int whichVariable,
337                          double multiplier = 1.0);
338    //@}
339
340private:
341    typedef struct {
342        double multiplier; // to use in computation
343        int affected; // variable or element affected
344        /*
345          0 - LB of variable affected
346          1 - UB of variable affected
347          2 - element in position (affected) affected
348        */
349        unsigned char affect;
350        unsigned char ubUsed; // nonzero if UB of this variable is used
351        /*
352           0 - use x*multiplier
353           1 - use multiplier/x
354           2 - if UB use min of current upper and x*multiplier, if LB use max of current lower and x*multiplier
355        */
356        unsigned char type; // type of computation
357    } boundElementAction;
358
359    /**@name Private member data */
360    //@{
361    /// Pointer back to model
362    OsiSolverInterface * model_;
363    /// Variable
364    int variable_;
365    /// Number of variables/elements affected
366    int numberAffected_;
367    /// Maximum number of variables/elements affected
368    int maximumAffected_;
369    /// Actions
370    boundElementAction * affected_;
371    //@}
372};
373#include "CbcHeuristic.hpp"
374/** heuristic - just picks up any good solution
375 */
376
377class CbcHeuristicDynamic3 : public CbcHeuristic {
378public:
379
380    // Default Constructor
381    CbcHeuristicDynamic3 ();
382
383    /* Constructor with model
384     */
385    CbcHeuristicDynamic3 (CbcModel & model);
386
387    // Copy constructor
388    CbcHeuristicDynamic3 ( const CbcHeuristicDynamic3 &);
389
390    // Destructor
391    ~CbcHeuristicDynamic3 ();
392
393    /// Clone
394    virtual CbcHeuristic * clone() const;
395
396    /// update model
397    virtual void setModel(CbcModel * model);
398
399    using CbcHeuristic::solution ;
400    /** returns 0 if no solution, 1 if valid solution.
401        Sets solution values if good, sets objective value (only if good)
402        We leave all variables which are at one at this node of the
403        tree to that value and will
404        initially set all others to zero.  We then sort all variables in order of their cost
405        divided by the number of entries in rows which are not yet covered.  We randomize that
406        value a bit so that ties will be broken in different ways on different runs of the heuristic.
407        We then choose the best one and set it to one and repeat the exercise.
408
409    */
410    virtual int solution(double & objectiveValue,
411                         double * newSolution);
412    /// Resets stuff if model changes
413    virtual void resetModel(CbcModel * model);
414    /// Returns true if can deal with "odd" problems e.g. sos type 2
415    virtual bool canDealWithOdd() const {
416        return true;
417    }
418
419protected:
420private:
421    /// Illegal Assignment operator
422    CbcHeuristicDynamic3 & operator=(const CbcHeuristicDynamic3& rhs);
423};
424
425#include "OsiBranchingObject.hpp"
426
427/** Define Special Linked Ordered Sets.
428
429*/
430class CoinWarmStartBasis;
431
432class OsiOldLink : public OsiSOS {
433
434public:
435
436    // Default Constructor
437    OsiOldLink ();
438
439    /** Useful constructor - A valid solution is if all variables are zero
440        apart from k*numberLink to (k+1)*numberLink-1 where k is 0 through
441        numberInSet-1.  The length of weights array is numberInSet.
442        For this constructor the variables in matrix are the numberInSet*numberLink
443        starting at first. If weights null then 0,1,2..
444    */
445    OsiOldLink (const OsiSolverInterface * solver, int numberMembers,
446                int numberLinks, int first,
447                const double * weights, int setNumber);
448    /** Useful constructor - A valid solution is if all variables are zero
449        apart from k*numberLink to (k+1)*numberLink-1 where k is 0 through
450        numberInSet-1.  The length of weights array is numberInSet.
451        For this constructor the variables are given by list - grouped.
452        If weights null then 0,1,2..
453    */
454    OsiOldLink (const OsiSolverInterface * solver, int numberMembers,
455                int numberLinks, int typeSOS, const int * which,
456                const double * weights, int setNumber);
457
458    // Copy constructor
459    OsiOldLink ( const OsiOldLink &);
460
461    /// Clone
462    virtual OsiObject * clone() const;
463
464    // Assignment operator
465    OsiOldLink & operator=( const OsiOldLink& rhs);
466
467    // Destructor
468    virtual ~OsiOldLink ();
469
470    using OsiObject::infeasibility ;
471    /// Infeasibility - large is 0.5
472    virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
473
474    using OsiObject::feasibleRegion ;
475    /** Set bounds to fix the variable at the current (integer) value.
476
477      Given an integer value, set the lower and upper bounds to fix the
478      variable. Returns amount it had to move variable.
479    */
480    virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
481
482    /** Creates a branching object
483
484      The preferred direction is set by \p way, 0 for down, 1 for up.
485    */
486    virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
487
488    /// Redoes data when sequence numbers change
489    virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
490
491    /// Number of links for each member
492    inline int numberLinks() const {
493        return numberLinks_;
494    }
495
496    /** \brief Return true if object can take part in normal heuristics
497    */
498    virtual bool canDoHeuristics() const {
499        return false;
500    }
501    /** \brief Return true if branch should only bound variables
502    */
503    virtual bool boundBranch() const {
504        return false;
505    }
506
507private:
508    /// data
509
510    /// Number of links
511    int numberLinks_;
512};
513/** Branching object for Linked ordered sets
514
515 */
516class OsiOldLinkBranchingObject : public OsiSOSBranchingObject {
517
518public:
519
520    // Default Constructor
521    OsiOldLinkBranchingObject ();
522
523    // Useful constructor
524    OsiOldLinkBranchingObject (OsiSolverInterface * solver,  const OsiOldLink * originalObject,
525                               int way,
526                               double separator);
527
528    // Copy constructor
529    OsiOldLinkBranchingObject ( const OsiOldLinkBranchingObject &);
530
531    // Assignment operator
532    OsiOldLinkBranchingObject & operator=( const OsiOldLinkBranchingObject& rhs);
533
534    /// Clone
535    virtual OsiBranchingObject * clone() const;
536
537    // Destructor
538    virtual ~OsiOldLinkBranchingObject ();
539
540    using OsiBranchingObject::branch ;
541    /// Does next branch and updates state
542    virtual double branch(OsiSolverInterface * solver);
543
544    using OsiBranchingObject::print ;
545    /** \brief Print something about branch - only if log level high
546    */
547    virtual void print(const OsiSolverInterface * solver = NULL);
548private:
549    /// data
550};
551/** Define data for one link
552
553*/
554
555
556class OsiOneLink {
557
558public:
559
560    // Default Constructor
561    OsiOneLink ();
562
563    /** Useful constructor -
564
565    */
566    OsiOneLink (const OsiSolverInterface * solver, int xRow, int xColumn, int xyRow,
567                const char * functionString);
568
569    // Copy constructor
570    OsiOneLink ( const OsiOneLink &);
571
572    // Assignment operator
573    OsiOneLink & operator=( const OsiOneLink& rhs);
574
575    // Destructor
576    virtual ~OsiOneLink ();
577
578    /// data
579
580    /// Row which defines x (if -1 then no x)
581    int xRow_;
582    /// Column which defines x
583    int xColumn_;
584    /// Output row
585    int xyRow;
586    /// Function
587    std::string function_;
588};
589/** Define Special Linked Ordered Sets. New style
590
591    members and weights may be stored in SOS object
592
593    This is for y and x*f(y) and z*g(y) etc
594
595*/
596
597
598class OsiLink : public OsiSOS {
599
600public:
601
602    // Default Constructor
603    OsiLink ();
604
605    /** Useful constructor -
606
607    */
608    OsiLink (const OsiSolverInterface * solver, int yRow,
609             int yColumn, double meshSize);
610
611    // Copy constructor
612    OsiLink ( const OsiLink &);
613
614    /// Clone
615    virtual OsiObject * clone() const;
616
617    // Assignment operator
618    OsiLink & operator=( const OsiLink& rhs);
619
620    // Destructor
621    virtual ~OsiLink ();
622
623    using OsiObject::infeasibility ;
624    /// Infeasibility - large is 0.5
625    virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
626
627    using OsiObject::feasibleRegion ;
628    /** Set bounds to fix the variable at the current (integer) value.
629
630      Given an integer value, set the lower and upper bounds to fix the
631      variable. Returns amount it had to move variable.
632    */
633    virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
634
635    /** Creates a branching object
636
637      The preferred direction is set by \p way, 0 for down, 1 for up.
638    */
639    virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
640
641    /// Redoes data when sequence numbers change
642    virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
643
644    /// Number of links for each member
645    inline int numberLinks() const {
646        return numberLinks_;
647    }
648
649    /** \brief Return true if object can take part in normal heuristics
650    */
651    virtual bool canDoHeuristics() const {
652        return false;
653    }
654    /** \brief Return true if branch should only bound variables
655    */
656    virtual bool boundBranch() const {
657        return false;
658    }
659
660private:
661    /// data
662    /// Current increment for y points
663    double meshSize_;
664    /// Links
665    OsiOneLink * data_;
666    /// Number of links
667    int numberLinks_;
668    /// Row which defines y
669    int yRow_;
670    /// Column which defines y
671    int yColumn_;
672};
673/** Branching object for Linked ordered sets
674
675 */
676class OsiLinkBranchingObject : public OsiTwoWayBranchingObject {
677
678public:
679
680    // Default Constructor
681    OsiLinkBranchingObject ();
682
683    // Useful constructor
684    OsiLinkBranchingObject (OsiSolverInterface * solver,  const OsiLink * originalObject,
685                            int way,
686                            double separator);
687
688    // Copy constructor
689    OsiLinkBranchingObject ( const OsiLinkBranchingObject &);
690
691    // Assignment operator
692    OsiLinkBranchingObject & operator=( const OsiLinkBranchingObject& rhs);
693
694    /// Clone
695    virtual OsiBranchingObject * clone() const;
696
697    // Destructor
698    virtual ~OsiLinkBranchingObject ();
699
700    using OsiBranchingObject::branch ;
701    /// Does next branch and updates state
702    virtual double branch(OsiSolverInterface * solver);
703
704    using OsiBranchingObject::print ;
705    /** \brief Print something about branch - only if log level high
706    */
707    virtual void print(const OsiSolverInterface * solver = NULL);
708private:
709    /// data
710};
711/** Define BiLinear objects
712
713    This models x*y where one or both are integer
714
715*/
716
717
718class OsiBiLinear : public OsiObject2 {
719
720public:
721
722    // Default Constructor
723    OsiBiLinear ();
724
725    /** Useful constructor -
726        This Adds in rows and variables to construct valid Linked Ordered Set
727        Adds extra constraints to match other x/y
728        So note not const solver
729    */
730    OsiBiLinear (OsiSolverInterface * solver, int xColumn,
731                 int yColumn, int xyRow, double coefficient,
732                 double xMesh, double yMesh,
733                 int numberExistingObjects = 0, const OsiObject ** objects = NULL );
734
735    /** Useful constructor -
736        This Adds in rows and variables to construct valid Linked Ordered Set
737        Adds extra constraints to match other x/y
738        So note not const model
739    */
740    OsiBiLinear (CoinModel * coinModel, int xColumn,
741                 int yColumn, int xyRow, double coefficient,
742                 double xMesh, double yMesh,
743                 int numberExistingObjects = 0, const OsiObject ** objects = NULL );
744
745    // Copy constructor
746    OsiBiLinear ( const OsiBiLinear &);
747
748    /// Clone
749    virtual OsiObject * clone() const;
750
751    // Assignment operator
752    OsiBiLinear & operator=( const OsiBiLinear& rhs);
753
754    // Destructor
755    virtual ~OsiBiLinear ();
756
757    using OsiObject::infeasibility ;
758    /// Infeasibility - large is 0.5
759    virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
760
761    using OsiObject::feasibleRegion ;
762    /** Set bounds to fix the variable at the current (integer) value.
763
764      Given an integer value, set the lower and upper bounds to fix the
765      variable. Returns amount it had to move variable.
766    */
767    virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
768
769    /** Creates a branching object
770
771      The preferred direction is set by \p way, 0 for down, 1 for up.
772    */
773    virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
774
775    /// Redoes data when sequence numbers change
776    virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
777
778    // This does NOT set mutable stuff
779    virtual double checkInfeasibility(const OsiBranchingInformation * info) const;
780
781    /** \brief Return true if object can take part in normal heuristics
782    */
783    virtual bool canDoHeuristics() const {
784        return false;
785    }
786    /** \brief Return true if branch should only bound variables
787    */
788    virtual bool boundBranch() const {
789        return (branchingStrategy_&4) != 0;
790    }
791    /// X column
792    inline int xColumn() const {
793        return xColumn_;
794    }
795    /// Y column
796    inline int yColumn() const {
797        return yColumn_;
798    }
799    /// X row
800    inline int xRow() const {
801        return xRow_;
802    }
803    /// Y row
804    inline int yRow() const {
805        return yRow_;
806    }
807    /// XY row
808    inline int xyRow() const {
809        return xyRow_;
810    }
811    /// Coefficient
812    inline double coefficient() const {
813        return coefficient_;
814    }
815    /// Set coefficient
816    inline void setCoefficient(double value) {
817        coefficient_ = value;
818    }
819    /// First lambda (of 4)
820    inline int firstLambda() const {
821        return firstLambda_;
822    }
823    /// X satisfied if less than this away from mesh
824    inline double xSatisfied() const {
825        return xSatisfied_;
826    }
827    inline void setXSatisfied(double value) {
828        xSatisfied_ = value;
829    }
830    /// Y satisfied if less than this away from mesh
831    inline double ySatisfied() const {
832        return ySatisfied_;
833    }
834    inline void setYSatisfied(double value) {
835        ySatisfied_ = value;
836    }
837    /// X other satisfied if less than this away from mesh
838    inline double xOtherSatisfied() const {
839        return xOtherSatisfied_;
840    }
841    inline void setXOtherSatisfied(double value) {
842        xOtherSatisfied_ = value;
843    }
844    /// Y other satisfied if less than this away from mesh
845    inline double yOtherSatisfied() const {
846        return yOtherSatisfied_;
847    }
848    inline void setYOtherSatisfied(double value) {
849        yOtherSatisfied_ = value;
850    }
851    /// X meshSize
852    inline double xMeshSize() const {
853        return xMeshSize_;
854    }
855    inline void setXMeshSize(double value) {
856        xMeshSize_ = value;
857    }
858    /// Y meshSize
859    inline double yMeshSize() const {
860        return yMeshSize_;
861    }
862    inline void setYMeshSize(double value) {
863        yMeshSize_ = value;
864    }
865    /// XY satisfied if two version differ by less than this
866    inline double xySatisfied() const {
867        return xySatisfied_;
868    }
869    inline void setXYSatisfied(double value) {
870        xySatisfied_ = value;
871    }
872    /// Set sizes and other stuff
873    void setMeshSizes(const OsiSolverInterface * solver, double x, double y);
874    /** branching strategy etc
875        bottom 2 bits
876        0 branch on either, 1 branch on x, 2 branch on y
877        next bit
878        4 set to say don't update coefficients
879        next bit
880        8 set to say don't use in feasible region
881        next bit
882        16 set to say - Always satisfied !!
883    */
884    inline int branchingStrategy() const {
885        return branchingStrategy_;
886    }
887    inline void setBranchingStrategy(int value) {
888        branchingStrategy_ = value;
889    }
890    /** Simple quadratic bound marker.
891        0 no
892        1 L if coefficient pos, G if negative i.e. value is ub on xy
893        2 G if coefficient pos, L if negative i.e. value is lb on xy
894        3 E
895        If bound then real coefficient is 1.0 and coefficient_ is bound
896    */
897    inline int boundType() const {
898        return boundType_;
899    }
900    inline void setBoundType(int value) {
901        boundType_ = value;
902    }
903    /// Does work of branching
904    void newBounds(OsiSolverInterface * solver, int way, short xOrY, double separator) const;
905    /// Updates coefficients - returns number updated
906    int updateCoefficients(const double * lower, const double * upper, double * objective,
907                           CoinPackedMatrix * matrix, CoinWarmStartBasis * basis) const;
908    /// Returns true value of single xyRow coefficient
909    double xyCoefficient(const double * solution) const;
910    /// Get LU coefficients from matrix
911    void getCoefficients(const OsiSolverInterface * solver, double xB[2], double yB[2], double xybar[4]) const;
912    /// Compute lambdas (third entry in each .B is current value) (nonzero if bad)
913    double computeLambdas(const double xB[3], const double yB[3], const double xybar[4], double lambda[4]) const;
914    /// Adds in data for extra row with variable coefficients
915    void addExtraRow(int row, double multiplier);
916    /// Sets infeasibility and other when pseudo shadow prices
917    void getPseudoShadow(const OsiBranchingInformation * info);
918    /// Gets sum of movements to correct value
919    double getMovement(const OsiBranchingInformation * info);
920
921protected:
922    /// Compute lambdas if coefficients not changing
923    void computeLambdas(const OsiSolverInterface * solver, double lambda[4]) const;
924    /// data
925
926    /// Coefficient
927    double coefficient_;
928    /// x mesh
929    double xMeshSize_;
930    /// y mesh
931    double yMeshSize_;
932    /// x satisfied if less than this away from mesh
933    double xSatisfied_;
934    /// y satisfied if less than this away from mesh
935    double ySatisfied_;
936    /// X other satisfied if less than this away from mesh
937    double xOtherSatisfied_;
938    /// Y other satisfied if less than this away from mesh
939    double yOtherSatisfied_;
940    /// xy satisfied if less than this away from true
941    double xySatisfied_;
942    /// value of x or y to branch about
943    mutable double xyBranchValue_;
944    /// x column
945    int xColumn_;
946    /// y column
947    int yColumn_;
948    /// First lambda (of 4)
949    int firstLambda_;
950    /** branching strategy etc
951        bottom 2 bits
952        0 branch on either, 1 branch on x, 2 branch on y
953        next bit
954        4 set to say don't update coefficients
955        next bit
956        8 set to say don't use in feasible region
957        next bit
958        16 set to say - Always satisfied !!
959    */
960    int branchingStrategy_;
961    /** Simple quadratic bound marker.
962        0 no
963        1 L if coefficient pos, G if negative i.e. value is ub on xy
964        2 G if coefficient pos, L if negative i.e. value is lb on xy
965        3 E
966        If bound then real coefficient is 1.0 and coefficient_ is bound
967    */
968    int boundType_;
969    /// x row
970    int xRow_;
971    /// y row (-1 if x*x)
972    int yRow_;
973    /// Output row
974    int xyRow_;
975    /// Convexity row
976    int convexity_;
977    /// Number of extra rows (coefficients to be modified)
978    int numberExtraRows_;
979    /// Multiplier for coefficient on row
980    double * multiplier_;
981    /// Row number
982    int * extraRow_;
983    /// Which chosen -1 none, 0 x, 1 y
984    mutable short chosen_;
985};
986/** Branching object for BiLinear objects
987
988 */
989class OsiBiLinearBranchingObject : public OsiTwoWayBranchingObject {
990
991public:
992
993    // Default Constructor
994    OsiBiLinearBranchingObject ();
995
996    // Useful constructor
997    OsiBiLinearBranchingObject (OsiSolverInterface * solver,  const OsiBiLinear * originalObject,
998                                int way,
999                                double separator, int chosen);
1000
1001    // Copy constructor
1002    OsiBiLinearBranchingObject ( const OsiBiLinearBranchingObject &);
1003
1004    // Assignment operator
1005    OsiBiLinearBranchingObject & operator=( const OsiBiLinearBranchingObject& rhs);
1006
1007    /// Clone
1008    virtual OsiBranchingObject * clone() const;
1009
1010    // Destructor
1011    virtual ~OsiBiLinearBranchingObject ();
1012
1013    using OsiBranchingObject::branch ;
1014    /// Does next branch and updates state
1015    virtual double branch(OsiSolverInterface * solver);
1016
1017    using OsiBranchingObject::print ;
1018    /** \brief Print something about branch - only if log level high
1019    */
1020    virtual void print(const OsiSolverInterface * solver = NULL);
1021    /** \brief Return true if branch should only bound variables
1022    */
1023    virtual bool boundBranch() const;
1024private:
1025    /// data
1026    /// 1 means branch on x, 2 branch on y
1027    short chosen_;
1028};
1029/** Define Continuous BiLinear objects for an == bound
1030
1031    This models x*y = b where both are continuous
1032
1033*/
1034
1035
1036class OsiBiLinearEquality : public OsiBiLinear {
1037
1038public:
1039
1040    // Default Constructor
1041    OsiBiLinearEquality ();
1042
1043    /** Useful constructor -
1044        This Adds in rows and variables to construct Ordered Set
1045        for x*y = b
1046        So note not const solver
1047    */
1048    OsiBiLinearEquality (OsiSolverInterface * solver, int xColumn,
1049                         int yColumn, int xyRow, double rhs,
1050                         double xMesh);
1051
1052    // Copy constructor
1053    OsiBiLinearEquality ( const OsiBiLinearEquality &);
1054
1055    /// Clone
1056    virtual OsiObject * clone() const;
1057
1058    // Assignment operator
1059    OsiBiLinearEquality & operator=( const OsiBiLinearEquality& rhs);
1060
1061    // Destructor
1062    virtual ~OsiBiLinearEquality ();
1063
1064    /// Possible improvement
1065    virtual double improvement(const OsiSolverInterface * solver) const;
1066    /** change grid
1067        if type 0 then use solution and make finer
1068        if 1 then back to original
1069        returns mesh size
1070    */
1071    double newGrid(OsiSolverInterface * solver, int type) const;
1072    /// Number of points
1073    inline int numberPoints() const {
1074        return numberPoints_;
1075    }
1076    inline void setNumberPoints(int value) {
1077        numberPoints_ = value;
1078    }
1079
1080private:
1081    /// Number of points
1082    int numberPoints_;
1083};
1084/// Define a single integer class - but one where you keep branching until fixed even if satisfied
1085
1086
1087class OsiSimpleFixedInteger : public OsiSimpleInteger {
1088
1089public:
1090
1091    /// Default Constructor
1092    OsiSimpleFixedInteger ();
1093
1094    /// Useful constructor - passed solver index
1095    OsiSimpleFixedInteger (const OsiSolverInterface * solver, int iColumn);
1096
1097    /// Useful constructor - passed solver index and original bounds
1098    OsiSimpleFixedInteger (int iColumn, double lower, double upper);
1099
1100    /// Useful constructor - passed simple integer
1101    OsiSimpleFixedInteger (const OsiSimpleInteger &);
1102
1103    /// Copy constructor
1104    OsiSimpleFixedInteger ( const OsiSimpleFixedInteger &);
1105
1106    /// Clone
1107    virtual OsiObject * clone() const;
1108
1109    /// Assignment operator
1110    OsiSimpleFixedInteger & operator=( const OsiSimpleFixedInteger& rhs);
1111
1112    /// Destructor
1113    virtual ~OsiSimpleFixedInteger ();
1114
1115    using OsiObject::infeasibility ;
1116    /// Infeasibility - large is 0.5
1117    virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
1118
1119    /** Creates a branching object
1120
1121      The preferred direction is set by \p way, 0 for down, 1 for up.
1122    */
1123    virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
1124protected:
1125    /// data
1126
1127};
1128/** Define a single variable class which is involved with OsiBiLinear objects.
1129    This is used so can make better decision on where to branch as it can look at
1130    all objects.
1131
1132    This version sees if it can re-use code from OsiSimpleInteger
1133    even if not an integer variable.  If not then need to duplicate code.
1134*/
1135
1136
1137class OsiUsesBiLinear : public OsiSimpleInteger {
1138
1139public:
1140
1141    /// Default Constructor
1142    OsiUsesBiLinear ();
1143
1144    /// Useful constructor - passed solver index
1145    OsiUsesBiLinear (const OsiSolverInterface * solver, int iColumn, int type);
1146
1147    /// Useful constructor - passed solver index and original bounds
1148    OsiUsesBiLinear (int iColumn, double lower, double upper, int type);
1149
1150    /// Useful constructor - passed simple integer
1151    OsiUsesBiLinear (const OsiSimpleInteger & rhs, int type);
1152
1153    /// Copy constructor
1154    OsiUsesBiLinear ( const OsiUsesBiLinear & rhs);
1155
1156    /// Clone
1157    virtual OsiObject * clone() const;
1158
1159    /// Assignment operator
1160    OsiUsesBiLinear & operator=( const OsiUsesBiLinear& rhs);
1161
1162    /// Destructor
1163    virtual ~OsiUsesBiLinear ();
1164
1165    using OsiObject::infeasibility ;
1166    /// Infeasibility - large is 0.5
1167    virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
1168
1169    /** Creates a branching object
1170
1171      The preferred direction is set by \p way, 0 for down, 1 for up.
1172    */
1173    virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
1174
1175    using OsiObject::feasibleRegion ;
1176    /** Set bounds to fix the variable at the current value.
1177
1178      Given an current value, set the lower and upper bounds to fix the
1179      variable. Returns amount it had to move variable.
1180    */
1181    virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
1182
1183    /// Add all bi-linear objects
1184    void addBiLinearObjects(OsiSolverLink * solver);
1185protected:
1186    /// data
1187    /// Number of bilinear objects (maybe could be more general)
1188    int numberBiLinear_;
1189    /// Type of variable - 0 continuous, 1 integer
1190    int type_;
1191    /// Objects
1192    OsiObject ** objects_;
1193};
1194/** This class chooses a variable to branch on
1195
1196    This is just as OsiChooseStrong but it fakes it so only
1197    first so many are looked at in this phase
1198
1199*/
1200
1201class OsiChooseStrongSubset  : public OsiChooseStrong {
1202
1203public:
1204
1205    /// Default Constructor
1206    OsiChooseStrongSubset ();
1207
1208    /// Constructor from solver (so we can set up arrays etc)
1209    OsiChooseStrongSubset (const OsiSolverInterface * solver);
1210
1211    /// Copy constructor
1212    OsiChooseStrongSubset (const OsiChooseStrongSubset &);
1213
1214    /// Assignment operator
1215    OsiChooseStrongSubset & operator= (const OsiChooseStrongSubset& rhs);
1216
1217    /// Clone
1218    virtual OsiChooseVariable * clone() const;
1219
1220    /// Destructor
1221    virtual ~OsiChooseStrongSubset ();
1222
1223    /** Sets up strong list and clears all if initialize is true.
1224        Returns number of infeasibilities.
1225        If returns -1 then has worked out node is infeasible!
1226    */
1227    virtual int setupList ( OsiBranchingInformation *info, bool initialize);
1228    /** Choose a variable
1229        Returns -
1230       -1 Node is infeasible
1231       0  Normal termination - we have a candidate
1232       1  All looks satisfied - no candidate
1233       2  We can change the bound on a variable - but we also have a strong branching candidate
1234       3  We can change the bound on a variable - but we have a non-strong branching candidate
1235       4  We can change the bound on a variable - no other candidates
1236       We can pick up branch from bestObjectIndex() and bestWhichWay()
1237       We can pick up a forced branch (can change bound) from firstForcedObjectIndex() and firstForcedWhichWay()
1238       If we have a solution then we can pick up from goodObjectiveValue() and goodSolution()
1239       If fixVariables is true then 2,3,4 are all really same as problem changed
1240    */
1241    virtual int chooseVariable( OsiSolverInterface * solver, OsiBranchingInformation *info, bool fixVariables);
1242
1243    /// Number of objects to use
1244    inline int numberObjectsToUse() const {
1245        return numberObjectsToUse_;
1246    }
1247    /// Set number of objects to use
1248    inline void setNumberObjectsToUse(int value) {
1249        numberObjectsToUse_ = value;
1250    }
1251
1252protected:
1253    // Data
1254    /// Number of objects to be used (and set in solver)
1255    int numberObjectsToUse_;
1256};
1257
1258#include <string>
1259
1260#include "CglStored.hpp"
1261
1262class CoinWarmStartBasis;
1263/** Stored Temporary Cut Generator Class - destroyed after first use */
1264class CglTemporary : public CglStored {
1265
1266public:
1267
1268
1269    /**@name Generate Cuts */
1270    //@{
1271    /** Generate Mixed Integer Stored cuts for the model of the
1272        solver interface, si.
1273
1274        Insert the generated cuts into OsiCut, cs.
1275
1276        This generator just looks at previously stored cuts
1277        and inserts any that are violated by enough
1278    */
1279    virtual void generateCuts( const OsiSolverInterface & si, OsiCuts & cs,
1280                               const CglTreeInfo info = CglTreeInfo()) const;
1281    //@}
1282
1283    /**@name Constructors and destructors */
1284    //@{
1285    /// Default constructor
1286    CglTemporary ();
1287
1288    /// Copy constructor
1289    CglTemporary (const CglTemporary & rhs);
1290
1291    /// Clone
1292    virtual CglCutGenerator * clone() const;
1293
1294    /// Assignment operator
1295    CglTemporary &
1296    operator=(const CglTemporary& rhs);
1297
1298    /// Destructor
1299    virtual
1300    ~CglTemporary ();
1301    //@}
1302
1303private:
1304
1305// Private member methods
1306
1307    // Private member data
1308};
1309//#############################################################################
1310
1311/**
1312
1313This is to allow the user to replace initialSolve and resolve
1314*/
1315
1316class OsiSolverLinearizedQuadratic : public OsiClpSolverInterface {
1317
1318public:
1319    //---------------------------------------------------------------------------
1320    /**@name Solve methods */
1321    //@{
1322    /// Solve initial LP relaxation
1323    virtual void initialSolve();
1324    //@}
1325
1326
1327    /**@name Constructors and destructors */
1328    //@{
1329    /// Default Constructor
1330    OsiSolverLinearizedQuadratic ();
1331    /// Useful constructor (solution should be good)
1332    OsiSolverLinearizedQuadratic(  ClpSimplex * quadraticModel);
1333    /// Clone
1334    virtual OsiSolverInterface * clone(bool copyData = true) const;
1335
1336    /// Copy constructor
1337    OsiSolverLinearizedQuadratic (const OsiSolverLinearizedQuadratic &);
1338
1339    /// Assignment operator
1340    OsiSolverLinearizedQuadratic & operator=(const OsiSolverLinearizedQuadratic& rhs);
1341
1342    /// Destructor
1343    virtual ~OsiSolverLinearizedQuadratic ();
1344
1345    //@}
1346
1347
1348    /**@name Sets and Gets */
1349    //@{
1350    /// Objective value of best solution found internally
1351    inline double bestObjectiveValue() const {
1352        return bestObjectiveValue_;
1353    }
1354    /// Best solution found internally
1355    const double * bestSolution() const {
1356        return bestSolution_;
1357    }
1358    /// Set special options
1359    inline void setSpecialOptions3(int value) {
1360        specialOptions3_ = value;
1361    }
1362    /// Get special options
1363    inline int specialOptions3() const {
1364        return specialOptions3_;
1365    }
1366    /// Copy of quadratic model if one
1367    ClpSimplex * quadraticModel() const {
1368        return quadraticModel_;
1369    }
1370    //@}
1371
1372    //---------------------------------------------------------------------------
1373
1374protected:
1375
1376
1377    /**@name functions */
1378    //@{
1379
1380    /**@name Private member data */
1381    //@{
1382    /// Objective value of best solution found internally
1383    double bestObjectiveValue_;
1384    /// Copy of quadratic model if one
1385    ClpSimplex * quadraticModel_;
1386    /// Best solution found internally
1387    double * bestSolution_;
1388    /**
1389       0 bit (1) - don't do mini B&B
1390       1 bit (2) - quadratic only in objective
1391    */
1392    int specialOptions3_;
1393    //@}
1394};
1395class ClpSimplex;
1396/** Return an approximate solution to a CoinModel.
1397    Lots of bounds may be odd to force a solution.
1398    mode = 0 just tries to get a continuous solution
1399*/
1400ClpSimplex * approximateSolution(CoinModel & coinModel,
1401                                 int numberPasses, double deltaTolerance,
1402                                 int mode = 0);
1403#endif
1404
Note: See TracBrowser for help on using the repository browser.