source/ui/nlpbuilder.cxx

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  The Contents of this file are made available subject to
00004  *  the terms of GNU Lesser General Public License Version 2.1.
00005  *
00006  *
00007  *    GNU Lesser General Public License Version 2.1
00008  *    =============================================
00009  *    Copyright 2005 by Kohei Yoshida.
00010  *    1039 Kingsway Dr., Apex, NC 27502, USA
00011  *
00012  *    This library is free software; you can redistribute it and/or
00013  *    modify it under the terms of the GNU Lesser General Public
00014  *    License version 2.1, as published by the Free Software Foundation.
00015  *
00016  *    This library is distributed in the hope that it will be useful,
00017  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  *    Lesser General Public License for more details.
00020  *
00021  *    You should have received a copy of the GNU Lesser General Public
00022  *    License along with this library; if not, write to the Free Software
00023  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00024  *    MA  02111-1307  USA
00025  *
00026  ************************************************************************/
00027 
00028 #include "nlpbuilder.hxx"
00029 #include "solver.hxx"
00030 #include "xcalc.hxx"
00031 #include "numeric/nlpmodel.hxx"
00032 #include "numeric/cellfuncobj.hxx"
00033 
00034 #include "com/sun/star/table/CellAddress.hpp"
00035 
00036 #include <list>
00037 #include <stdio.h>
00038 
00039 using std::list;
00040 using scsolver::numeric::nlp::Model;
00041 using scsolver::numeric::CellFuncObj;
00042 using com::sun::star::table::CellAddress;
00043 
00044 namespace scsolver {
00045 
00046 class NlpModelBuilderImpl
00047 {
00048 public:
00049         NlpModelBuilderImpl( SolverImpl* p ) :
00050                 m_pSolverImpl(p),
00051         m_pFuncObj(NULL)
00052         {
00053         }
00054 
00055         ~NlpModelBuilderImpl() throw()
00056         {
00057         }
00058 
00059         Model getModel()
00060         {
00061                 Model model;
00062 
00063         if (m_pFuncObj)
00064         {
00065             m_pFuncObj->setTargetCell(m_ObjFormAddr);
00066             model.setFuncObject(m_pFuncObj);
00067             CalcInterface* pCalc = m_pSolverImpl->getCalcInterface();
00068             list<CellAddress>::iterator it,
00069                 itBeg = m_cnDecVarAddr.begin(),
00070                 itEnd = m_cnDecVarAddr.end();
00071             for (it = itBeg; it != itEnd; ++it)
00072             {
00073                 model.pushVar(pCalc->getCellValue(*it));
00074                 m_pFuncObj->appendDecVarCell(*it);
00075             }
00076             model.print();
00077         }
00078 
00079                 return model;
00080         }
00081 
00082         void setObjectiveFormulaAddress( CellAddress addr )
00083         {
00084                 m_ObjFormAddr = addr;
00085         }
00086 
00087         void clearDecVarAddresses()
00088         {
00089                 m_cnDecVarAddr.clear();
00090         }
00091 
00092         void appendDecVarAddress( CellAddress addr )
00093         {
00094                 m_cnDecVarAddr.push_back(addr);
00095         }
00096 
00097     void setFuncObj(CellFuncObj* p)
00098     {
00099         m_pFuncObj = p;
00100     }
00101 
00102 private:
00103         SolverImpl* m_pSolverImpl;
00104         CellAddress m_ObjFormAddr;
00105         list<CellAddress> m_cnDecVarAddr;
00106     CellFuncObj* m_pFuncObj;
00107 };
00108 
00109 //-----------------------------------------------------------------
00110 
00111 NlpModelBuilder::NlpModelBuilder( SolverImpl* p ) :
00112         m_pImpl( new NlpModelBuilderImpl(p) )
00113 {
00114         fprintf( stderr, "NlpModelBuilder ctor\n" );
00115 }
00116 
00117 NlpModelBuilder::~NlpModelBuilder() throw()
00118 {
00119         fprintf( stderr, "NlpModelBuilder dtor\n" );
00120 }
00121 
00122 void NlpModelBuilder::setFuncObj(CellFuncObj* p)
00123 {
00124     m_pImpl->setFuncObj(p);
00125 }
00126 
00127 void NlpModelBuilder::setObjectiveFormulaAddress( CellAddress addr )
00128 {
00129         m_pImpl->setObjectiveFormulaAddress(addr);
00130 }
00131 
00132 void NlpModelBuilder::clearDecVarAddresses()
00133 {
00134         m_pImpl->clearDecVarAddresses();
00135 }
00136 
00137 void NlpModelBuilder::appendDecVarAddress( CellAddress addr )
00138 {
00139         m_pImpl->appendDecVarAddress(addr);
00140 }
00141 
00142 Model NlpModelBuilder::getModel() const
00143 {
00144         return m_pImpl->getModel();
00145 }
00146 
00147 }

Generated on Mon Jul 28 09:13:20 2008 for scsolver by  doxygen 1.5.3