LibreOffice Module sccomp (master) 1
SolverComponent.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#pragma once
21
22#include <com/sun/star/sheet/XSolver.hpp>
23#include <com/sun/star/sheet/XSolverDescription.hpp>
24#include <com/sun/star/table/CellAddress.hpp>
25#include <com/sun/star/lang/XServiceInfo.hpp>
30#include <unotools/resmgr.hxx>
31
32#include <unordered_map>
33
34namespace com::sun::star::table { class XCell; }
35
36// hash map for the coefficients of a dependent cell (objective or constraint)
37// The size of each vector is the number of columns (variable cells) plus one, first entry is initial value.
38
40{
41 size_t operator()( const css::table::CellAddress& rAddress ) const;
42};
43
44inline bool AddressEqual( const css::table::CellAddress& rAddr1, const css::table::CellAddress& rAddr2 )
45{
46 return rAddr1.Sheet == rAddr2.Sheet && rAddr1.Column == rAddr2.Column && rAddr1.Row == rAddr2.Row;
47}
48
50{
51 bool operator()( const css::table::CellAddress& rAddr1, const css::table::CellAddress& rAddr2 ) const;
52};
53
54typedef std::unordered_map< css::table::CellAddress, std::vector<double>, ScSolverCellHash, ScSolverCellEqual > ScSolverCellHashMap;
55
56typedef cppu::WeakImplHelper<
57 css::sheet::XSolver,
58 css::sheet::XSolverDescription,
59 css::lang::XServiceInfo >
61
64 public comphelper::OPropertyArrayUsageHelper< SolverComponent >,
66{
67protected:
68 // settings
69 css::uno::Reference< css::sheet::XSpreadsheetDocument > mxDoc;
70 css::table::CellAddress maObjective;
71 css::uno::Sequence< css::table::CellAddress > maVariables;
72 css::uno::Sequence< css::sheet::SolverConstraint > maConstraints;
74 // set via XPropertySet
77 sal_Int32 mnTimeout;
78 sal_Int32 mnEpsilonLevel;
80 // results
83 css::uno::Sequence< double > maSolution;
84 OUString maStatus;
85
86 static OUString GetResourceString(TranslateId aId);
87 static css::uno::Reference<css::table::XCell> GetCell(
88 const css::uno::Reference<css::sheet::XSpreadsheetDocument>& xDoc,
89 const css::table::CellAddress& rPos );
90 static void SetValue(
91 const css::uno::Reference<css::sheet::XSpreadsheetDocument>& xDoc,
92 const css::table::CellAddress& rPos, double fValue );
93 static double GetValue(
94 const css::uno::Reference<css::sheet::XSpreadsheetDocument>& xDoc,
95 const css::table::CellAddress& rPos );
96
97public:
99 virtual ~SolverComponent() override;
100
102 DECLARE_XTYPEPROVIDER()
103
104 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override;
105 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; // from OPropertySetHelper
106 virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const override; // from OPropertyArrayUsageHelper
107
108 // XSolver
109 virtual css::uno::Reference< css::sheet::XSpreadsheetDocument > SAL_CALL getDocument() override;
110 virtual void SAL_CALL setDocument( const css::uno::Reference<
111 css::sheet::XSpreadsheetDocument >& _document ) override;
112 virtual css::table::CellAddress SAL_CALL getObjective() override;
113 virtual void SAL_CALL setObjective( const css::table::CellAddress& _objective ) override;
114 virtual css::uno::Sequence< css::table::CellAddress > SAL_CALL getVariables() override;
115 virtual void SAL_CALL setVariables( const css::uno::Sequence<
116 css::table::CellAddress >& _variables ) override;
117 virtual css::uno::Sequence< css::sheet::SolverConstraint > SAL_CALL getConstraints() override;
118 virtual void SAL_CALL setConstraints( const css::uno::Sequence<
119 css::sheet::SolverConstraint >& _constraints ) override;
120 virtual sal_Bool SAL_CALL getMaximize() override;
121 virtual void SAL_CALL setMaximize( sal_Bool _maximize ) override;
122
123 virtual sal_Bool SAL_CALL getSuccess() override;
124 virtual double SAL_CALL getResultValue() override;
125 virtual css::uno::Sequence< double > SAL_CALL getSolution() override;
126
127 virtual void SAL_CALL solve() override = 0;
128
129 // XSolverDescription
130 virtual OUString SAL_CALL getComponentDescription() override = 0;
131 virtual OUString SAL_CALL getStatusDescription() override;
132 virtual OUString SAL_CALL getPropertyDescription( const OUString& aPropertyName ) override;
133
134 // XServiceInfo
135 virtual OUString SAL_CALL getImplementationName() override = 0;
136 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
137 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
138};
139
140/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
cppu::WeakImplHelper< css::sheet::XSolver, css::sheet::XSolverDescription, css::lang::XServiceInfo > SolverComponent_Base
std::unordered_map< css::table::CellAddress, std::vector< double >, ScSolverCellHash, ScSolverCellEqual > ScSolverCellHashMap
bool AddressEqual(const css::table::CellAddress &rAddr1, const css::table::CellAddress &rAddr2)
virtual css::uno::Sequence< css::sheet::SolverConstraint > SAL_CALL getConstraints() override
virtual css::uno::Sequence< css::table::CellAddress > SAL_CALL getVariables() override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
virtual void SAL_CALL setVariables(const css::uno::Sequence< css::table::CellAddress > &_variables) override
virtual sal_Bool SAL_CALL getSuccess() override
virtual sal_Bool SAL_CALL getMaximize() override
virtual void SAL_CALL solve() override=0
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
sal_Int32 mnEpsilonLevel
virtual css::uno::Reference< css::sheet::XSpreadsheetDocument > SAL_CALL getDocument() override
virtual double SAL_CALL getResultValue() override
css::uno::Sequence< double > maSolution
virtual ~SolverComponent() override
virtual OUString SAL_CALL getImplementationName() override=0
virtual OUString SAL_CALL getComponentDescription() override=0
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
static css::uno::Reference< css::table::XCell > GetCell(const css::uno::Reference< css::sheet::XSpreadsheetDocument > &xDoc, const css::table::CellAddress &rPos)
virtual OUString SAL_CALL getPropertyDescription(const OUString &aPropertyName) override
css::uno::Reference< css::sheet::XSpreadsheetDocument > mxDoc
css::uno::Sequence< css::sheet::SolverConstraint > maConstraints
css::table::CellAddress maObjective
static double GetValue(const css::uno::Reference< css::sheet::XSpreadsheetDocument > &xDoc, const css::table::CellAddress &rPos)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
static void SetValue(const css::uno::Reference< css::sheet::XSpreadsheetDocument > &xDoc, const css::table::CellAddress &rPos, double fValue)
virtual void SAL_CALL setObjective(const css::table::CellAddress &_objective) override
static OUString GetResourceString(TranslateId aId)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getStatusDescription() override
virtual css::uno::Sequence< double > SAL_CALL getSolution() override
css::uno::Sequence< css::table::CellAddress > maVariables
virtual css::table::CellAddress SAL_CALL getObjective() override
virtual void SAL_CALL setDocument(const css::uno::Reference< css::sheet::XSpreadsheetDocument > &_document) override
virtual void SAL_CALL setConstraints(const css::uno::Sequence< css::sheet::SolverConstraint > &_constraints) override
virtual void SAL_CALL setMaximize(sal_Bool _maximize) override
bool operator()(const css::table::CellAddress &rAddr1, const css::table::CellAddress &rAddr2) const
size_t operator()(const css::table::CellAddress &rAddress) const
unsigned char sal_Bool
#define DECLARE_XINTERFACE()