Modelib: Fichier source de Constraint.cpp

Page principale | Liste des namespaces | Hiérarchie des classes | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de namespace | Membres de classe | Membres de fichier

# Constraint.cpp

Aller à la documentation de ce fichier.

    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 #include "Config.h"
    00033 #include "Constraint.h"
    00034 #include "Model.h"
    00035 #include <iostream>
    00036
    00037 namespace Modelib {
    00038
    00043 Constraint::Constraint(Model & _m,VarId _id)
    00044 {
    00045   model = &_m;
    00046   id = _id;
    00047 }
    00048
    00053 Constraint::Constraint(const Model & _m,VarId _id)
    00054 {
    00055   model = const_cast<Model *>( &_m );
    00056   id = _id;
    00057 }
    00058
    00065 bool Constraint::Relax( float lagrangianValue )
    00066 {
    00067     //si le modèle est défini on appellera la fonction
    00068     //RelaxConstraint qui effectue la tache
    00069     if(model)
    00070     {
    00071         return model->RelaxConstraint( id, lagrangianValue );
    00072     }
    00073     else
    00074         cerr << "Warning in Constraint::Relax : undefined Model" << endl;
    00075     return false;
    00076 }
    00077
    00082 LagrangianParam Constraint::GetLagrangianParam() const
    00083 {
    00084    return LagrangianParam(const_cast<Model &>(*model),id);
    00085 }
    00086
    00090 void Constraint::Rename( const std::string & name )
    00091 {
    00092     //si le modèle est défini on appellera la fonction
    00093     //RenameConstraint qui effectue la tache
    00094     if(model)
    00095         model->RenameConstraint( id, name );
    00096     else
    00097         cerr << "Warning in Constraint::Rename : undefined Model" << endl;
    00098 }
    00099
    00104 void Constraint::AddExpr(const Expr & expr)
    00105 {
    00106     //si le modèle est défini on appellera la fonction
    00107     //AddToConstraint qui effectue la tache
    00108     if(model)
    00109         model->AddToConstraint( id, expr );
    00110     else
    00111         cerr << "Warning in Constraint::AddExpr : undefined Model" << endl;
    00112
    00113 }
    00114
    00117 Expr Constraint::GetExpr(bool secondMember) const
    00118 {
    00119     //si le modèle est défini on appellera la fonction
    00120     //GetRelaxedConstraintExpr qui effectue la tache
    00121     if(model)
    00122     {
    00123         Expr retour = model->GetRelaxedConstraintExpr( id, false );
    00124         if(!secondMember)
    00125            retour -= retour.GetConstant();
    00126         return retour;
    00127     }
    00128     else
    00129         cerr << "Warning in Constraint::GetExpr : undefined Model" << endl;
    00130     return Expr();
    00131 }
    00132
    00135 Expr Constraint::GetRelaxedExpr(bool secondMember) const
    00136 {
    00137     //si le modèle est défini on appellera la fonction
    00138     //GetRelaxedConstraintExpr qui effectue la tache
    00139     if(model)
    00140     {
    00141         Expr retour = model->GetRelaxedConstraintExpr( id, true );
    00142         if(!secondMember)
    00143            retour -= retour.GetConstant();
    00144         return retour;
    00145     }
    00146     else
    00147         cerr << "Warning in Constraint::GetRelaxedExpr : undefined Model" << endl;
    00148     return Expr();
    00149 }
    00150
    00153 float Constraint::GetSecondMember() const
    00154 {
    00155     //si le modèle est défini on appellera la fonction
    00156     //GetSecondMember qui effectue la tache
    00157     if(model)
    00158         return model->GetSecondMember( id );
    00159     else
    00160         cerr << "Warning in Constraint::GetSecondMember : undefined Model" << endl;
    00161     return 0.0f;
    00162
    00163 }
    00164
    00167 void Constraint::SetSecondMember(float value)
    00168 {
    00169     //si le modèle est défini on appellera la fonction
    00170     //SetSecondMember qui effectue la tache
    00171     if(model)
    00172         model->SetSecondMember( id,value );
    00173     else
    00174         cerr << "Warning in Constraint::GetExpr : undefined Model" << endl;
    00175 }
    00176
    00177 #ifdef COMPILE_FOR_PYTHON
    00178     #include "py_Constraint.cxx"
    00179 #endif
    00180
    00181
    00182 }