From 6ba90804b5da7b7e5f2bf752da433aaae16c975b Mon Sep 17 00:00:00 2001 From: Niklas Nebel Date: Fri, 15 Feb 2008 14:19:59 +0000 Subject: moved from module scext --- sccomp/prj/build.lst | 4 + sccomp/prj/d.lst | 9 + sccomp/source/solver/exports.map | 9 + sccomp/source/solver/makefile.mk | 84 +++++ sccomp/source/solver/solver.cxx | 727 +++++++++++++++++++++++++++++++++++++++ sccomp/source/solver/solver.hrc | 53 +++ sccomp/source/solver/solver.hxx | 152 ++++++++ sccomp/source/solver/solver.src | 84 +++++ 8 files changed, 1122 insertions(+) create mode 100644 sccomp/prj/build.lst create mode 100644 sccomp/prj/d.lst create mode 100644 sccomp/source/solver/exports.map create mode 100644 sccomp/source/solver/makefile.mk create mode 100644 sccomp/source/solver/solver.cxx create mode 100644 sccomp/source/solver/solver.hrc create mode 100644 sccomp/source/solver/solver.hxx create mode 100644 sccomp/source/solver/solver.src (limited to 'sccomp') diff --git a/sccomp/prj/build.lst b/sccomp/prj/build.lst new file mode 100644 index 000000000000..03978ee76cda --- /dev/null +++ b/sccomp/prj/build.lst @@ -0,0 +1,4 @@ +scx scext : offuh comphelper lpsolve tools transex3 rsc NULL +scx scext usr1 - all scx_mkout NULL +scx scext\prj get - all scx_prj NULL +scx scext\source\solver nmake - all scx_solver NULL diff --git a/sccomp/prj/d.lst b/sccomp/prj/d.lst new file mode 100644 index 000000000000..f31644cf5e8c --- /dev/null +++ b/sccomp/prj/d.lst @@ -0,0 +1,9 @@ +mkdir: %COMMON_DEST%\bin%_EXT%\hid +..\%COMMON_OUTDIR%\misc\*.hid %COMMON_DEST%\bin%_EXT%\hid\*.hid +..\%__SRC%\bin\*.dll %_DEST%\bin%_EXT%\*.dll +..\%__SRC%\class\*.jar %_DEST%\bin%_EXT%\*.jar +..\%__SRC%\lib\lib*.so %_DEST%\lib%_EXT% +..\%__SRC%\lib\*.dylib %_DEST%\lib%_EXT%\*.dylib +..\%__SRC%\lib\*.sl %_DEST%\lib%_EXT%\*.sl +..\%__SRC%\bin\*.bin %_DEST%\bin%_EXT%\*.bin +..\%__SRC%\bin\*.res %_DEST%\bin%_EXT%\*.res diff --git a/sccomp/source/solver/exports.map b/sccomp/source/solver/exports.map new file mode 100644 index 000000000000..fe0280ec6c21 --- /dev/null +++ b/sccomp/source/solver/exports.map @@ -0,0 +1,9 @@ +SOLVER_1_0 { + global: + component_getImplementationEnvironment; + component_getFactory; + component_writeInfo; + + local: + *; +}; diff --git a/sccomp/source/solver/makefile.mk b/sccomp/source/solver/makefile.mk new file mode 100644 index 000000000000..de438a2fa3c3 --- /dev/null +++ b/sccomp/source/solver/makefile.mk @@ -0,0 +1,84 @@ +#************************************************************************* +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: nn $ $Date: 2008-02-15 15:19:59 $ +# +# The Contents of this file are made available subject to +# the terms of GNU Lesser General Public License Version 2.1. +# +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2005 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=scext +TARGET=solver + +ENABLE_EXCEPTIONS=TRUE +USE_DEFFILE=TRUE +LIBTARGET=NO + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SLOFILES=$(SLO)$/solver.obj + +SRS1NAME=$(TARGET) +SRC1FILES=solver.src + +# --- Library ----------------------------------- + +SHL1TARGET= $(TARGET)$(UPD)$(DLLPOSTFIX) + +SHL1OBJS= $(SLOFILES) + +SHL1STDLIBS= $(COMPHELPERLIB) \ + $(CPPUHELPERLIB) \ + $(CPPULIB) \ + $(SALLIB) \ + $(TOOLSLIB) \ + $(LPSOLVELIB) + +SHL1DEPN= makefile.mk +SHL1DEF= $(MISC)$/$(SHL1TARGET).def +SHL1VERSIONMAP= exports.map +DEF1NAME= $(SHL1TARGET) + +# --- Resources -------------------------------- + +RESLIB1LIST=$(SRS)$/solver.srs + +RESLIB1NAME=solver +RESLIB1SRSFILES=$(RESLIB1LIST) + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + + diff --git a/sccomp/source/solver/solver.cxx b/sccomp/source/solver/solver.cxx new file mode 100644 index 000000000000..9fc4dadfb6bd --- /dev/null +++ b/sccomp/source/solver/solver.cxx @@ -0,0 +1,727 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: solver.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: nn $ $Date: 2008-02-15 15:19:59 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#undef LANGUAGE_NONE +#define WINAPI __stdcall +#define LoadInverseLib FALSE +#define LoadLanguageLib FALSE +#include +#undef LANGUAGE_NONE + +#include "solver.hxx" +#include "solver.hrc" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +using namespace com::sun::star; + +using ::rtl::OUString; + +#define C2U(constAsciiStr) (::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( constAsciiStr ) )) + +#define STR_NONNEGATIVE "NonNegative" +#define STR_INTEGER "Integer" +#define STR_TIMEOUT "Timeout" +#define STR_EPSILONLEVEL "EpsilonLevel" +#define STR_LIMITBBDEPTH "LimitBBDepth" + +// ----------------------------------------------------------------------- +// Resources from tools are used for translated strings + +static ResMgr* pSolverResMgr = NULL; + +OUString lcl_GetResourceString( sal_uInt32 nId ) +{ + if (!pSolverResMgr) + pSolverResMgr = CREATEVERSIONRESMGR( solver ); + + return String( ResId( nId, *pSolverResMgr ) ); +} + +// ----------------------------------------------------------------------- + +namespace +{ + enum + { + PROP_NONNEGATIVE, + PROP_INTEGER, + PROP_TIMEOUT, + PROP_EPSILONLEVEL, + PROP_LIMITBBDEPTH + }; +} + +// ----------------------------------------------------------------------- + +// hash map for the coefficients of a dependent cell (objective or constraint) +// The size of each vector is the number of columns (variable cells) plus one, first entry is initial value. + +struct ScSolverCellHash +{ + size_t operator()( const table::CellAddress& rAddress ) const + { + return ( rAddress.Sheet << 24 ) | ( rAddress.Column << 16 ) | rAddress.Row; + } +}; + +inline bool AddressEqual( const table::CellAddress& rAddr1, const table::CellAddress& rAddr2 ) +{ + return rAddr1.Sheet == rAddr2.Sheet && rAddr1.Column == rAddr2.Column && rAddr1.Row == rAddr2.Row; +} + +struct ScSolverCellEqual +{ + bool operator()( const table::CellAddress& rAddr1, const table::CellAddress& rAddr2 ) const + { + return AddressEqual( rAddr1, rAddr2 ); + } +}; + +typedef std::hash_map< table::CellAddress, std::vector, ScSolverCellHash, ScSolverCellEqual > ScSolverCellHashMap; + +// ----------------------------------------------------------------------- + +uno::Reference lcl_GetCell( const uno::Reference& xDoc, + const table::CellAddress& rPos ) +{ + uno::Reference xSheets( xDoc->getSheets(), uno::UNO_QUERY ); + uno::Reference xSheet( xSheets->getByIndex( rPos.Sheet ), uno::UNO_QUERY ); + return xSheet->getCellByPosition( rPos.Column, rPos.Row ); +} + +OUString lcl_GetString( const uno::Reference& xDoc, const table::CellAddress& rPos ) +{ + uno::Reference xText( lcl_GetCell( xDoc, rPos ), uno::UNO_QUERY ); + return xText->getString(); +} + +void lcl_SetString( const uno::Reference& xDoc, + const table::CellAddress& rPos, const OUString& rString ) +{ + uno::Reference xText( lcl_GetCell( xDoc, rPos ), uno::UNO_QUERY ); + xText->setString( rString ); +} + +void lcl_SetValue( const uno::Reference& xDoc, + const table::CellAddress& rPos, double fValue ) +{ + lcl_GetCell( xDoc, rPos )->setValue( fValue ); +} + +double lcl_GetValue( const uno::Reference& xDoc, + const table::CellAddress& rPos ) +{ + return lcl_GetCell( xDoc, rPos )->getValue(); +} + +OUString lcl_FormatCellRef( const uno::Reference& xDoc, const table::CellAddress& rPos ) +{ + uno::Reference xFact( xDoc, uno::UNO_QUERY ); + uno::Reference xConv( xFact->createInstance( + OUString::createFromAscii( "com.sun.star.table.CellAddressConversion" ) ), uno::UNO_QUERY ); + xConv->setPropertyValue( OUString::createFromAscii( "Address" ), uno::makeAny( rPos ) ); + OUString aRet; + xConv->getPropertyValue( OUString::createFromAscii( "UserInterfaceRepresentation" ) ) >>= aRet; + return aRet; +} + +bool lcl_ParseCellRef( table::CellAddress& rPos, + const uno::Reference& xDoc, + const OUString& rStr ) +{ + uno::Reference xFact( xDoc, uno::UNO_QUERY ); + uno::Reference xConv( xFact->createInstance( + OUString::createFromAscii( "com.sun.star.table.CellAddressConversion" ) ), uno::UNO_QUERY ); + try + { + xConv->setPropertyValue( OUString::createFromAscii( "UserInterfaceRepresentation" ), uno::makeAny( rStr ) ); + } + catch ( lang::IllegalArgumentException& ) + { + return false; // no valid ref + } + xConv->getPropertyValue( OUString::createFromAscii( "Address" ) ) >>= rPos; + return true; +} + +bool lcl_ParseRangeRef( table::CellRangeAddress& rRange, + const uno::Reference& xDoc, + const OUString& rStr ) +{ + uno::Reference xFact( xDoc, uno::UNO_QUERY ); + uno::Reference xConv( xFact->createInstance( + OUString::createFromAscii( "com.sun.star.table.CellRangeAddressConversion" ) ), uno::UNO_QUERY ); + try + { + xConv->setPropertyValue( OUString::createFromAscii( "UserInterfaceRepresentation" ), uno::makeAny( rStr ) ); + } + catch ( lang::IllegalArgumentException& ) + { + return false; // no valid ref + } + xConv->getPropertyValue( OUString::createFromAscii( "Address" ) ) >>= rRange; + return true; +} + +// ------------------------------------------------------------------------- + +SolverComponent::SolverComponent( const uno::Reference& /* rSMgr */ ) : + OPropertyContainer( GetBroadcastHelper() ), + mbMaximize( sal_True ), + mbNonNegative( sal_False ), + mbInteger( sal_False ), + mnTimeout( 100 ), + mnEpsilonLevel( 0 ), + mbLimitBBDepth( sal_True ), + mbSuccess( sal_False ), + mfResultValue( 0.0 ) +{ + // for XPropertySet implementation: + registerProperty( C2U(STR_NONNEGATIVE), PROP_NONNEGATIVE, 0, &mbNonNegative, getCppuType( &mbNonNegative ) ); + registerProperty( C2U(STR_INTEGER), PROP_INTEGER, 0, &mbInteger, getCppuType( &mbInteger ) ); + registerProperty( C2U(STR_TIMEOUT), PROP_TIMEOUT, 0, &mnTimeout, getCppuType( &mnTimeout ) ); + registerProperty( C2U(STR_EPSILONLEVEL), PROP_EPSILONLEVEL, 0, &mnEpsilonLevel, getCppuType( &mnEpsilonLevel ) ); + registerProperty( C2U(STR_LIMITBBDEPTH), PROP_LIMITBBDEPTH, 0, &mbLimitBBDepth, getCppuType( &mbLimitBBDepth ) ); +} + +SolverComponent::~SolverComponent() +{ +} + +IMPLEMENT_FORWARD_XINTERFACE2( SolverComponent, SolverComponent_Base, OPropertyContainer ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( SolverComponent, SolverComponent_Base, OPropertyContainer ) + +cppu::IPropertyArrayHelper* SolverComponent::createArrayHelper() const +{ + uno::Sequence aProps; + describeProperties( aProps ); + return new cppu::OPropertyArrayHelper( aProps ); +} + +cppu::IPropertyArrayHelper& SAL_CALL SolverComponent::getInfoHelper() +{ + return *getArrayHelper(); +} + +uno::Reference SAL_CALL SolverComponent::getPropertySetInfo() throw(uno::RuntimeException) +{ + return createPropertySetInfo( getInfoHelper() ); +} + +// XSolverDescription + +OUString SAL_CALL SolverComponent::getComponentDescription() throw (uno::RuntimeException) +{ + return lcl_GetResourceString( RID_SOLVER_COMPONENT ); +} + +OUString SAL_CALL SolverComponent::getStatusDescription() throw (uno::RuntimeException) +{ + return maStatus; +} + +OUString SAL_CALL SolverComponent::getPropertyDescription( const OUString& rPropertyName ) throw (uno::RuntimeException) +{ + sal_uInt32 nResId = 0; + sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName ); + switch (nHandle) + { + case PROP_NONNEGATIVE: + nResId = RID_PROPERTY_NONNEGATIVE; + break; + case PROP_INTEGER: + nResId = RID_PROPERTY_INTEGER; + break; + case PROP_TIMEOUT: + nResId = RID_PROPERTY_TIMEOUT; + break; + case PROP_EPSILONLEVEL: + nResId = RID_PROPERTY_EPSILONLEVEL; + break; + case PROP_LIMITBBDEPTH: + nResId = RID_PROPERTY_LIMITBBDEPTH; + break; + default: + { + // unknown - leave empty + } + } + OUString aRet; + if ( nResId ) + aRet = lcl_GetResourceString( nResId ); + return aRet; +} + +// XSolver: settings + +uno::Reference SAL_CALL SolverComponent::getDocument() throw(uno::RuntimeException) +{ + return mxDoc; +} + +void SAL_CALL SolverComponent::setDocument( const uno::Reference& _document ) + throw(uno::RuntimeException) +{ + mxDoc = _document; +} + +table::CellAddress SAL_CALL SolverComponent::getObjective() throw(uno::RuntimeException) +{ + return maObjective; +} + +void SAL_CALL SolverComponent::setObjective( const table::CellAddress& _objective ) throw(uno::RuntimeException) +{ + maObjective = _objective; +} + +uno::Sequence SAL_CALL SolverComponent::getVariables() throw(uno::RuntimeException) +{ + return maVariables; +} + +void SAL_CALL SolverComponent::setVariables( const uno::Sequence& _variables ) + throw(uno::RuntimeException) +{ + maVariables = _variables; +} + +uno::Sequence SAL_CALL SolverComponent::getConstraints() throw(uno::RuntimeException) +{ + return maConstraints; +} + +void SAL_CALL SolverComponent::setConstraints( const uno::Sequence& _constraints ) + throw(uno::RuntimeException) +{ + maConstraints = _constraints; +} + +sal_Bool SAL_CALL SolverComponent::getMaximize() throw(uno::RuntimeException) +{ + return mbMaximize; +} + +void SAL_CALL SolverComponent::setMaximize( sal_Bool _maximize ) throw(uno::RuntimeException) +{ + mbMaximize = _maximize; +} + +// XSolver: get results + +sal_Bool SAL_CALL SolverComponent::getSuccess() throw(uno::RuntimeException) +{ + return mbSuccess; +} + +double SAL_CALL SolverComponent::getResultValue() throw(uno::RuntimeException) +{ + return mfResultValue; +} + +uno::Sequence SAL_CALL SolverComponent::getSolution() throw(uno::RuntimeException) +{ + return maSolution; +} + +// ------------------------------------------------------------------------- + +void SAL_CALL SolverComponent::solve() throw(uno::RuntimeException) +{ + uno::Reference xModel( mxDoc, uno::UNO_QUERY ); + if ( !xModel.is() ) + throw uno::RuntimeException(); + + maStatus = OUString(); + mbSuccess = false; + + if ( mnEpsilonLevel < EPS_TIGHT || mnEpsilonLevel > EPS_BAGGY ) + { + maStatus = lcl_GetResourceString( RID_ERROR_EPSILONLEVEL ); + return; + } + + xModel->lockControllers(); + + // collect variables in vector (?) + + std::vector aVariableCells; + for (sal_Int32 nPos=0; nPos>= aCellAddr ) + aCellsHash[aCellAddr].reserve( nVariables + 1 ); // constraints: right hand side + } + + // set all variables to zero + //! store old values? + //! use old values as initial values? + std::vector::const_iterator aVarIter; + for ( aVarIter = aVariableCells.begin(); aVarIter != aVariableCells.end(); ++aVarIter ) + { + lcl_SetValue( mxDoc, *aVarIter, 0.0 ); + } + + // read initial values from all dependent cells + ScSolverCellHashMap::iterator aCellsIter; + for ( aCellsIter = aCellsHash.begin(); aCellsIter != aCellsHash.end(); ++aCellsIter ) + { + double fValue = lcl_GetValue( mxDoc, aCellsIter->first ); + aCellsIter->second.push_back( fValue ); // store as first element, as-is + } + + // loop through variables + for ( aVarIter = aVariableCells.begin(); aVarIter != aVariableCells.end(); ++aVarIter ) + { + lcl_SetValue( mxDoc, *aVarIter, 1.0 ); // set to 1 to examine influence + + // read value change from all dependent cells + for ( aCellsIter = aCellsHash.begin(); aCellsIter != aCellsHash.end(); ++aCellsIter ) + { + double fChanged = lcl_GetValue( mxDoc, aCellsIter->first ); + double fInitial = aCellsIter->second.front(); + aCellsIter->second.push_back( fChanged - fInitial ); + } + + lcl_SetValue( mxDoc, *aVarIter, 2.0 ); // minimal test for linearity + + for ( aCellsIter = aCellsHash.begin(); aCellsIter != aCellsHash.end(); ++aCellsIter ) + { + double fInitial = aCellsIter->second.front(); + double fCoeff = aCellsIter->second.back(); // last appended: coefficient for this variable + double fTwo = lcl_GetValue( mxDoc, aCellsIter->first ); + + bool bLinear = rtl::math::approxEqual( fTwo, fInitial + 2.0 * fCoeff ) || + rtl::math::approxEqual( fInitial, fTwo - 2.0 * fCoeff ); + // second comparison is needed in case fTwo is zero + if ( !bLinear ) + maStatus = lcl_GetResourceString( RID_ERROR_NONLINEAR ); + } + + lcl_SetValue( mxDoc, *aVarIter, 0.0 ); // set back to zero for examining next variable + } + + xModel->unlockControllers(); + + if ( maStatus.getLength() ) + return; + + // + // build lp_solve model + // + + lprec* lp = make_lp( 0, nVariables ); + if ( !lp ) + return; + + set_outputfile( lp, const_cast( "" ) ); // no output + + // set objective function + + const std::vector& rObjCoeff = aCellsHash[maObjective]; + REAL* pObjVal = new REAL[nVariables+1]; + pObjVal[0] = 0.0; // ignored + for (nVar=0; nVar>= aRightAddr ) + bRightCell = true; // cell specified as right-hand side + else + rRightAny >>= fDirectValue; // constant value + + table::CellAddress aLeftAddr = maConstraints[nConstrPos].Left; + + const std::vector& rLeftCoeff = aCellsHash[aLeftAddr]; + REAL* pValues = new REAL[nVariables+1]; + pValues[0] = 0.0; // ignored? + for (nVar=0; nVar& rRightCoeff = aCellsHash[aRightAddr]; + // modify pValues with rhs coefficients + for (nVar=0; nVar SolverComponent_getSupportedServiceNames() +{ + uno::Sequence< OUString > aServiceNames( 1 ); + aServiceNames[ 0 ] = OUString::createFromAscii( "com.sun.star.sheet.Solver" ); + return aServiceNames; +} + +OUString SolverComponent_getImplementationName() +{ + return OUString::createFromAscii( "com.sun.star.comp.Calc.Solver" ); +} + +OUString SAL_CALL SolverComponent::getImplementationName() throw(uno::RuntimeException) +{ + return SolverComponent_getImplementationName(); +} + +sal_Bool SAL_CALL SolverComponent::supportsService( const OUString& rServiceName ) throw(uno::RuntimeException) +{ + const uno::Sequence< OUString > aServices = SolverComponent_getSupportedServiceNames(); + const OUString* pArray = aServices.getConstArray(); + const OUString* pArrayEnd = pArray + aServices.getLength(); + return ::std::find( pArray, pArrayEnd, rServiceName ) != pArrayEnd; +} + +uno::Sequence SAL_CALL SolverComponent::getSupportedServiceNames() throw(uno::RuntimeException) +{ + return SolverComponent_getSupportedServiceNames(); +} + +uno::Reference SolverComponent_createInstance( const uno::Reference& rSMgr ) + throw(uno::Exception) +{ + return (cppu::OWeakObject*) new SolverComponent( rSMgr ); +} + +// ------------------------------------------------------------------------- + +extern "C" +{ + void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ) + { + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; + } + + // ------------------------------------------------------------------------- + + sal_Bool SAL_CALL component_writeInfo( void* /*pServiceManager*/, void* pRegistryKey ) + { + if (pRegistryKey) + { + try + { + uno::Reference xNewKey; + sal_Int32 nPos; + + xNewKey = reinterpret_cast< registry::XRegistryKey * >( pRegistryKey )->createKey( SolverComponent_getImplementationName() ); + xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) ); + const uno::Sequence< OUString > & rSNL1 = SolverComponent_getSupportedServiceNames(); + const OUString * pArray1 = rSNL1.getConstArray(); + for ( nPos = rSNL1.getLength(); nPos--; ) + xNewKey->createKey( pArray1[nPos] ); + + return sal_True; + } + catch (registry::InvalidRegistryException &) + { + OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); + } + } + return sal_False; + } + + // ------------------------------------------------------------------------- + + void* SAL_CALL component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) + { + OUString aImplName( OUString::createFromAscii( pImplName ) ); + void* pRet = 0; + + if( pServiceManager ) + { + uno::Reference< lang::XSingleComponentFactory > xFactory; + if( aImplName.equals( SolverComponent_getImplementationName() ) ) + xFactory = cppu::createSingleComponentFactory( + SolverComponent_createInstance, + OUString::createFromAscii( pImplName ), + SolverComponent_getSupportedServiceNames() ); + + if( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + return pRet; + } +} + diff --git a/sccomp/source/solver/solver.hrc b/sccomp/source/solver/solver.hrc new file mode 100644 index 000000000000..12bbcc7adef5 --- /dev/null +++ b/sccomp/source/solver/solver.hrc @@ -0,0 +1,53 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: solver.hrc,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: nn $ $Date: 2008-02-15 15:19:59 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ +#ifndef SOLVER_HRC +#define SOLVER_HRC + +#define SOLVER_RESOURCE_START 1000 + +#define RID_SOLVER_COMPONENT (SOLVER_RESOURCE_START) +#define RID_PROPERTY_NONNEGATIVE (SOLVER_RESOURCE_START + 1) +#define RID_PROPERTY_INTEGER (SOLVER_RESOURCE_START + 2) +#define RID_PROPERTY_TIMEOUT (SOLVER_RESOURCE_START + 3) +#define RID_PROPERTY_EPSILONLEVEL (SOLVER_RESOURCE_START + 4) +#define RID_PROPERTY_LIMITBBDEPTH (SOLVER_RESOURCE_START + 5) +#define RID_ERROR_NONLINEAR (SOLVER_RESOURCE_START + 6) +#define RID_ERROR_EPSILONLEVEL (SOLVER_RESOURCE_START + 7) +#define RID_ERROR_INFEASIBLE (SOLVER_RESOURCE_START + 8) +#define RID_ERROR_UNBOUNDED (SOLVER_RESOURCE_START + 9) +#define RID_ERROR_TIMEOUT (SOLVER_RESOURCE_START + 10) + +#endif + diff --git a/sccomp/source/solver/solver.hxx b/sccomp/source/solver/solver.hxx new file mode 100644 index 000000000000..a22625c63382 --- /dev/null +++ b/sccomp/source/solver/solver.hxx @@ -0,0 +1,152 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: solver.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: nn $ $Date: 2008-02-15 15:19:59 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef SOLVER_HXX +#define SOLVER_HXX + +#ifndef _COM_SUN_STAR_SHEET_XSOLVER_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_SHEET_XSOLVERDESCRIPTION_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_UNO_XCOMPONENTCONTEXT_HPP_ +#include +#endif +#ifndef _CPPUHELPER_IMPLBASE3_HXX_ +#include +#endif + +#ifndef _COMPHELPER_BROADCASTHELPER_HXX_ +#include +#endif +#ifndef _COMPHELPER_PROPERTYCONTAINER_HXX_ +#include +#endif +#ifndef _COMPHELPER_PROPERTY_ARRAY_HELPER_HXX_ +#include +#endif + +typedef cppu::WeakImplHelper3< + com::sun::star::sheet::XSolver, + com::sun::star::sheet::XSolverDescription, + com::sun::star::lang::XServiceInfo > + SolverComponent_Base; + +class SolverComponent : public comphelper::OMutexAndBroadcastHelper, + public comphelper::OPropertyContainer, + public comphelper::OPropertyArrayUsageHelper< SolverComponent >, + public SolverComponent_Base +{ + // settings + com::sun::star::uno::Reference< com::sun::star::sheet::XSpreadsheetDocument > mxDoc; + com::sun::star::table::CellAddress maObjective; + com::sun::star::uno::Sequence< com::sun::star::table::CellAddress > maVariables; + com::sun::star::uno::Sequence< com::sun::star::sheet::SolverConstraint > maConstraints; + sal_Bool mbMaximize; + // set via XPropertySet + sal_Bool mbNonNegative; + sal_Bool mbInteger; + sal_Int32 mnTimeout; + sal_Int32 mnEpsilonLevel; + sal_Bool mbLimitBBDepth; + // results + sal_Bool mbSuccess; + double mfResultValue; + com::sun::star::uno::Sequence< double > maSolution; + rtl::OUString maStatus; + +public: + SolverComponent( const com::sun::star::uno::Reference< + com::sun::star::uno::XComponentContext >& rxMSF ); + virtual ~SolverComponent(); + + DECLARE_XINTERFACE() + DECLARE_XTYPEPROVIDER() + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); + virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); // from OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const; // from OPropertyArrayUsageHelper + + // XSolver + virtual ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument > SAL_CALL getDocument() + throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDocument( const ::com::sun::star::uno::Reference< + ::com::sun::star::sheet::XSpreadsheetDocument >& _document ) + throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::table::CellAddress SAL_CALL getObjective() throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setObjective( const ::com::sun::star::table::CellAddress& _objective ) + throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::table::CellAddress > SAL_CALL getVariables() + throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setVariables( const ::com::sun::star::uno::Sequence< + ::com::sun::star::table::CellAddress >& _variables ) + throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::SolverConstraint > SAL_CALL getConstraints() + throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setConstraints( const ::com::sun::star::uno::Sequence< + ::com::sun::star::sheet::SolverConstraint >& _constraints ) + throw(::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getMaximize() throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setMaximize( ::sal_Bool _maximize ) throw(::com::sun::star::uno::RuntimeException); + + virtual ::sal_Bool SAL_CALL getSuccess() throw(::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getResultValue() throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< double > SAL_CALL getSolution() + throw(::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL solve() throw(::com::sun::star::uno::RuntimeException); + + // XSolverDescription + virtual ::rtl::OUString SAL_CALL getComponentDescription() throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getStatusDescription() throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getPropertyDescription( const ::rtl::OUString& aPropertyName ) + throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() + throw(::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() + throw(::com::sun::star::uno::RuntimeException); +}; + +#endif + diff --git a/sccomp/source/solver/solver.src b/sccomp/source/solver/solver.src new file mode 100644 index 000000000000..756bfc5974b5 --- /dev/null +++ b/sccomp/source/solver/solver.src @@ -0,0 +1,84 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: solver.src,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: nn $ $Date: 2008-02-15 15:19:59 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#include "solver.hrc" + +String RID_SOLVER_COMPONENT +{ + Text [ en-US ] = "%PRODUCTNAME Linear Solver"; +}; + +String RID_PROPERTY_NONNEGATIVE +{ + Text [ en-US ] = "Assume variables as non-negative"; +}; +String RID_PROPERTY_INTEGER +{ + Text [ en-US ] = "Assume variables as integer"; +}; +String RID_PROPERTY_TIMEOUT +{ + Text [ en-US ] = "Solving time limit (seconds)"; +}; +String RID_PROPERTY_EPSILONLEVEL +{ + Text [ en-US ] = "Epsilon level (0-3)"; +}; +String RID_PROPERTY_LIMITBBDEPTH +{ + Text [ en-US ] = "Limit branch-and-bound depth"; +}; + +String RID_ERROR_NONLINEAR +{ + Text [ en-US ] = "The model is not linear."; +}; +String RID_ERROR_EPSILONLEVEL +{ + Text [ en-US ] = "The epsilon level is invalid."; +}; +String RID_ERROR_INFEASIBLE +{ + Text [ en-US ] = "The model is infeasible. Check limiting conditions."; +}; +String RID_ERROR_UNBOUNDED +{ + Text [ en-US ] = "The model is unbounded."; +}; +String RID_ERROR_TIMEOUT +{ + Text [ en-US ] = "The time limit was reached."; +}; + -- cgit v1.2.3