00001 /* 00002 Copyright (c) 2005, Quentin Lequy and Romain Gaucher 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or 00006 without modification, are permitted provided that the following 00007 conditions are met: 00008 00009 * Redistributions of source code must retain the above copyright 00010 notice, this list of conditions and the following disclaimer. 00011 00012 * Redistributions in binary form must reproduce the above copyright 00013 notice, this list of conditions and the following disclaimer in the 00014 documentation and/or other materials provided with the distribution. 00015 00016 * Neither the name of Quentin Lequy or Romain Gaucher nor the names 00017 of its contributors may be used to endorse or promote products 00018 derived from this software without specific prior written permission. 00019 00020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00021 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00022 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00023 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00024 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00025 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00026 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00027 AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 */ 00031 00032 #ifndef __CONSTRAINT_H 00033 #define __CONSTRAINT_H 00034 00035 #include "Constant.h" 00036 #include "LagrangianParam.h" 00037 #include <string> 00038 00039 namespace Modelib { 00040 00041 class Model; 00042 class Expr; 00043 00045 00050 class Constraint 00051 { 00052 Model * model; 00053 VarId id; 00054 00055 public: 00057 Constraint():model(0),id(0) {}; 00058 00059 Constraint(Model & _m,VarId _id); 00060 Constraint( const Model & _m,VarId _id); 00061 00063 Constraint( const Constraint & _c) 00064 { 00065 model = _c.model; 00066 id = _c.id; 00067 } 00068 00069 Constraint operator= ( const Constraint & _c) 00070 { 00071 model = _c.model; 00072 id = _c.id; 00073 return *this; 00074 } 00075 00079 VarId GetId() const { return id;} 00080 00084 Model * GetModel() const { return model;} 00085 00086 bool Relax( float lagrangianValue = -Infinity); 00087 00088 LagrangianParam GetLagrangianParam() const; 00089 00090 void Rename( const std::string & name ); 00091 00092 void AddExpr(const Expr &); 00093 00094 Expr GetExpr(bool secondMember = false) const; 00095 00096 Expr GetRelaxedExpr(bool secondMember = false) const; 00097 00098 void SetSecondMember(float); 00099 00100 float GetSecondMember() const; 00101 00102 float GetValue() const; 00103 00104 ~Constraint() {} 00105 }; 00106 00107 inline bool operator==( const Constraint & c1, const Constraint & c2) 00108 { 00109 return c1.GetModel() == c2.GetModel() && c1.GetId() == c2.GetId(); 00110 } 00111 00112 #ifdef COMPILE_FOR_PYTHON 00113 void export_Constraint(); 00114 #endif 00115 00116 } 00117 00118 #endif