00001 /* $Id: simplify.cpp 490 2011-01-14 16:07:12Z pbelotti $ 00002 * 00003 * Name: simplify.cpp 00004 * Author: Pietro Belotti 00005 * Purpose: symbolic expression simplifier 00006 * 00007 * (C) Carnegie-Mellon University, 2006-10. 00008 * This file is licensed under the Eclipse Public License (EPL) 00009 */ 00010 00011 #include "CouenneExpression.hpp" 00012 #include "CouenneExprOp.hpp" 00013 #include "CouenneExprUnary.hpp" 00014 #include "CouenneExprConst.hpp" 00015 00016 using namespace Couenne; 00017 00018 // simplify n-ary expression f (g_1(x), g_2(x)... g_n(x)) 00019 00020 expression *exprOp:: simplify () { 00021 00022 // Simplify arguments g_1(x), g_2(x)... g_n(x) first 00023 for (int i=0; i<nargs_; i++) { 00024 00025 expression *subst; 00026 00027 if ((subst = arglist_ [i] -> simplify ())) { 00028 00029 delete arglist_ [i]; 00030 arglist_ [i] = subst; 00031 } 00032 } 00033 00034 return NULL; 00035 } 00036 00037 00038 // simplify unary operators 00039 00040 expression *exprUnary:: simplify () { 00041 00042 register expression *subst; 00043 00044 // Simplify argument g(x) of this expression f(g(x)) 00045 if ((subst = argument_ -> simplify ())) { 00046 00047 delete argument_; 00048 argument_ = subst; 00049 00050 // g(x) is a constant k, therefore return f (k) 00051 if (subst -> Type () == CONST) { 00052 00053 expression *ret = new exprConst (operator () ()); 00054 argument_ = NULL; 00055 delete subst; 00056 00057 return ret; 00058 } 00059 } 00060 00061 return NULL; 00062 }