diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-10-29 09:59:24 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-10-30 21:55:34 +0200 |
commit | 881ea76399a76599e17688f335f4f164d4d29413 (patch) | |
tree | 97be2e9f91ec8f5b47662580335bce1c6090a5d5 /sccomp | |
parent | 83f50dee5b4add87cf30903aeb0e44e0d4f04682 (diff) |
Prepare for removal of non-const operator[] from Sequence in sccomp
Change-Id: Ic55d553c85dd0abb92b6b7f223a437c8c2ca0700
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124383
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sccomp')
-rw-r--r-- | sccomp/qa/unit/SwarmSolverTest.cxx | 157 | ||||
-rw-r--r-- | sccomp/qa/unit/solver.cxx | 9 | ||||
-rw-r--r-- | sccomp/source/solver/LpsolveSolver.cxx | 4 |
3 files changed, 78 insertions, 92 deletions
diff --git a/sccomp/qa/unit/SwarmSolverTest.cxx b/sccomp/qa/unit/SwarmSolverTest.cxx index 78cfccaaa376..030822b9cdb4 100644 --- a/sccomp/qa/unit/SwarmSolverTest.cxx +++ b/sccomp/qa/unit/SwarmSolverTest.cxx @@ -127,14 +127,14 @@ void SwarmSolverTest::testVariableBounded() uno::Sequence<table::CellAddress> aVariables{ { 0, 1, 0 } }; // constraints - uno::Sequence<sheet::SolverConstraint> aConstraints(2); - aConstraints[0].Left = table::CellAddress(0, 1, 0); - aConstraints[0].Operator = sheet::SolverConstraintOperator_LESS_EQUAL; - aConstraints[0].Right <<= 100.0; - - aConstraints[1].Left = table::CellAddress(0, 1, 0); - aConstraints[1].Operator = sheet::SolverConstraintOperator_GREATER_EQUAL; - aConstraints[1].Right <<= -100.0; + uno::Sequence<sheet::SolverConstraint> aConstraints{ + { /* [0] Left */ table::CellAddress(0, 1, 0), + /* Operator */ sheet::SolverConstraintOperator_LESS_EQUAL, + /* Right */ uno::Any(100.0) }, + { /* [1] Left */ table::CellAddress(0, 1, 0), + /* Operator */ sheet::SolverConstraintOperator_GREATER_EQUAL, + /* Right */ uno::Any(-100.0) } + }; // initialize solver xSolver->setDocument(xDocument); @@ -178,18 +178,17 @@ void SwarmSolverTest::testVariableConstrained() uno::Sequence<table::CellAddress> aVariables{ { 0, 1, 0 } }; // constraints - uno::Sequence<sheet::SolverConstraint> aConstraints(3); - aConstraints[0].Left = table::CellAddress(0, 1, 0); - aConstraints[0].Operator = sheet::SolverConstraintOperator_GREATER_EQUAL; - aConstraints[0].Right <<= -50000.0; - - aConstraints[1].Left = table::CellAddress(0, 1, 0); - aConstraints[1].Operator = sheet::SolverConstraintOperator_LESS_EQUAL; - aConstraints[1].Right <<= 0.0; - - aConstraints[2].Left = table::CellAddress(0, 1, 1); - aConstraints[2].Operator = sheet::SolverConstraintOperator_GREATER_EQUAL; - aConstraints[2].Right <<= 10.0; + uno::Sequence<sheet::SolverConstraint> aConstraints{ + { /* [0] Left */ table::CellAddress(0, 1, 0), + /* Operator */ sheet::SolverConstraintOperator_GREATER_EQUAL, + /* Right */ uno::Any(-50000.0) }, + { /* [1] Left */ table::CellAddress(0, 1, 0), + /* Operator */ sheet::SolverConstraintOperator_LESS_EQUAL, + /* Right */ uno::Any(0.0) }, + { /* [2] Left */ table::CellAddress(0, 1, 1), + /* Operator */ sheet::SolverConstraintOperator_GREATER_EQUAL, + /* Right */ uno::Any(10.0) } + }; // initialize solver xSolver->setDocument(xDocument); @@ -233,23 +232,20 @@ void SwarmSolverTest::testTwoVariables() uno::Sequence<table::CellAddress> aVariables{ { 0, 1, 2 }, { 0, 1, 3 } }; // constraints - uno::Sequence<sheet::SolverConstraint> aConstraints(4); - - aConstraints[0].Left = table::CellAddress(0, 1, 2); - aConstraints[0].Operator = sheet::SolverConstraintOperator_GREATER_EQUAL; - aConstraints[0].Right <<= -100.0; - - aConstraints[1].Left = table::CellAddress(0, 1, 3); - aConstraints[1].Operator = sheet::SolverConstraintOperator_GREATER_EQUAL; - aConstraints[1].Right <<= -100.0; - - aConstraints[2].Left = table::CellAddress(0, 1, 2); - aConstraints[2].Operator = sheet::SolverConstraintOperator_LESS_EQUAL; - aConstraints[2].Right <<= 100.0; - - aConstraints[3].Left = table::CellAddress(0, 1, 3); - aConstraints[3].Operator = sheet::SolverConstraintOperator_LESS_EQUAL; - aConstraints[3].Right <<= 100.0; + uno::Sequence<sheet::SolverConstraint> aConstraints{ + { /* [0] Left */ table::CellAddress(0, 1, 2), + /* Operator */ sheet::SolverConstraintOperator_GREATER_EQUAL, + /* Right */ uno::Any(-100.0) }, + { /* [1] Left */ table::CellAddress(0, 1, 3), + /* Operator */ sheet::SolverConstraintOperator_GREATER_EQUAL, + /* Right */ uno::Any(-100.0) }, + { /* [2] Left */ table::CellAddress(0, 1, 2), + /* Operator */ sheet::SolverConstraintOperator_LESS_EQUAL, + /* Right */ uno::Any(100.0) }, + { /* [3] Left */ table::CellAddress(0, 1, 3), + /* Operator */ sheet::SolverConstraintOperator_LESS_EQUAL, + /* Right */ uno::Any(100.0) } + }; // initialize solver xSolver->setDocument(xDocument); @@ -299,55 +295,44 @@ void SwarmSolverTest::testMultipleVariables() }; // constraints - uno::Sequence<sheet::SolverConstraint> aConstraints(12); - - aConstraints[0].Left = table::CellAddress(0, 1, 5); - aConstraints[0].Operator = sheet::SolverConstraintOperator_GREATER_EQUAL; - aConstraints[0].Right <<= table::CellAddress(0, 1, 6); - - aConstraints[1].Left = table::CellAddress(0, 2, 5); - aConstraints[1].Operator = sheet::SolverConstraintOperator_GREATER_EQUAL; - aConstraints[1].Right <<= table::CellAddress(0, 2, 6); - - aConstraints[2].Left = table::CellAddress(0, 3, 5); - aConstraints[2].Operator = sheet::SolverConstraintOperator_GREATER_EQUAL; - aConstraints[2].Right <<= table::CellAddress(0, 3, 6); - - aConstraints[3].Left = table::CellAddress(0, 4, 5); - aConstraints[3].Operator = sheet::SolverConstraintOperator_GREATER_EQUAL; - aConstraints[3].Right <<= table::CellAddress(0, 4, 6); - - aConstraints[4].Left = table::CellAddress(0, 6, 1); - aConstraints[4].Operator = sheet::SolverConstraintOperator_GREATER_EQUAL; - aConstraints[4].Right <<= 0.0; - - aConstraints[5].Left = table::CellAddress(0, 6, 2); - aConstraints[5].Operator = sheet::SolverConstraintOperator_GREATER_EQUAL; - aConstraints[5].Right <<= 0.0; - - aConstraints[6].Left = table::CellAddress(0, 6, 3); - aConstraints[6].Operator = sheet::SolverConstraintOperator_GREATER_EQUAL; - aConstraints[6].Right <<= 0.0; - - aConstraints[7].Left = table::CellAddress(0, 6, 4); - aConstraints[7].Operator = sheet::SolverConstraintOperator_GREATER_EQUAL; - aConstraints[7].Right <<= 0.0; - - aConstraints[8].Left = table::CellAddress(0, 6, 1); - aConstraints[8].Operator = sheet::SolverConstraintOperator_LESS_EQUAL; - aConstraints[8].Right <<= 10000.0; - - aConstraints[9].Left = table::CellAddress(0, 6, 2); - aConstraints[9].Operator = sheet::SolverConstraintOperator_LESS_EQUAL; - aConstraints[9].Right <<= 10000.0; - - aConstraints[10].Left = table::CellAddress(0, 6, 3); - aConstraints[10].Operator = sheet::SolverConstraintOperator_LESS_EQUAL; - aConstraints[10].Right <<= 10000.0; - - aConstraints[11].Left = table::CellAddress(0, 6, 4); - aConstraints[11].Operator = sheet::SolverConstraintOperator_LESS_EQUAL; - aConstraints[11].Right <<= 10000.0; + uno::Sequence<sheet::SolverConstraint> aConstraints{ + { /* [ 0] Left */ table::CellAddress(0, 1, 5), + /* Operator */ sheet::SolverConstraintOperator_GREATER_EQUAL, + /* Right */ uno::Any(table::CellAddress(0, 1, 6)) }, + { /* [ 1] Left */ table::CellAddress(0, 2, 5), + /* Operator */ sheet::SolverConstraintOperator_GREATER_EQUAL, + /* Right */ uno::Any(table::CellAddress(0, 2, 6)) }, + { /* [ 2] Left */ table::CellAddress(0, 3, 5), + /* Operator */ sheet::SolverConstraintOperator_GREATER_EQUAL, + /* Right */ uno::Any(table::CellAddress(0, 3, 6)) }, + { /* [ 3] Left */ table::CellAddress(0, 4, 5), + /* Operator */ sheet::SolverConstraintOperator_GREATER_EQUAL, + /* Right */ uno::Any(table::CellAddress(0, 4, 6)) }, + { /* [ 4] Left */ table::CellAddress(0, 6, 1), + /* Operator */ sheet::SolverConstraintOperator_GREATER_EQUAL, + /* Right */ uno::Any(0.0) }, + { /* [ 5] Left */ table::CellAddress(0, 6, 2), + /* Operator */ sheet::SolverConstraintOperator_GREATER_EQUAL, + /* Right */ uno::Any(0.0) }, + { /* [ 6] Left */ table::CellAddress(0, 6, 3), + /* Operator */ sheet::SolverConstraintOperator_GREATER_EQUAL, + /* Right */ uno::Any(0.0) }, + { /* [ 7] Left */ table::CellAddress(0, 6, 4), + /* Operator */ sheet::SolverConstraintOperator_GREATER_EQUAL, + /* Right */ uno::Any(0.0) }, + { /* [ 8] Left */ table::CellAddress(0, 6, 1), + /* Operator */ sheet::SolverConstraintOperator_LESS_EQUAL, + /* Right */ uno::Any(10000.0) }, + { /* [ 9] Left */ table::CellAddress(0, 6, 2), + /* Operator */ sheet::SolverConstraintOperator_LESS_EQUAL, + /* Right */ uno::Any(10000.0) }, + { /* [10] Left */ table::CellAddress(0, 6, 3), + /* Operator */ sheet::SolverConstraintOperator_LESS_EQUAL, + /* Right */ uno::Any(10000.0) }, + { /* [11] Left */ table::CellAddress(0, 6, 4), + /* Operator */ sheet::SolverConstraintOperator_LESS_EQUAL, + /* Right */ uno::Any(10000.0) } + }; // initialize solver xSolver->setDocument(xDocument); diff --git a/sccomp/qa/unit/solver.cxx b/sccomp/qa/unit/solver.cxx index eedbce69f274..c4df7b644643 100644 --- a/sccomp/qa/unit/solver.cxx +++ b/sccomp/qa/unit/solver.cxx @@ -90,10 +90,11 @@ void LpSolverTest::testSolver(OUString const & rName) uno::Sequence<table::CellAddress> aVariables { {0, 0, 0 } }; // constraints - uno::Sequence<sheet::SolverConstraint> aConstraints(1); - aConstraints[0].Left = table::CellAddress(0, 0, 0); - aConstraints[0].Operator = sheet::SolverConstraintOperator_LESS_EQUAL; - aConstraints[0].Right <<= 5.0; + uno::Sequence<sheet::SolverConstraint> aConstraints{ + { /* Left */ table::CellAddress(0, 0, 0), + /* Operator */ sheet::SolverConstraintOperator_LESS_EQUAL, + /* Right */ uno::Any(5.0) } + }; // initialize solver xSolver->setDocument( m_xDocument ); diff --git a/sccomp/source/solver/LpsolveSolver.cxx b/sccomp/source/solver/LpsolveSolver.cxx index 229c5f0c3dbe..1053f53fa0ee 100644 --- a/sccomp/source/solver/LpsolveSolver.cxx +++ b/sccomp/source/solver/LpsolveSolver.cxx @@ -58,6 +58,7 @@ #include <com/sun/star/table/CellAddress.hpp> #include <unotools/resmgr.hxx> #include <rtl/math.hxx> +#include <algorithm> #include <memory> #include <vector> @@ -308,8 +309,7 @@ void SAL_CALL LpsolveSolver::solve() REAL* pResultVar = nullptr; get_ptr_variables( lp, &pResultVar ); - for (nVar=0; nVar<nVariables; nVar++) - maSolution[nVar] = pResultVar[nVar]; + std::copy_n(pResultVar, nVariables, maSolution.getArray()); mfResultValue = get_objective( lp ); } |