<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openoffice.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Tent</id>
	<title>Apache OpenOffice Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openoffice.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Tent"/>
	<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/wiki/Special:Contributions/Tent"/>
	<updated>2026-11-28T09:32:39Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.14</generator>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Optimization_Solver&amp;diff=17899</id>
		<title>Optimization Solver</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Optimization_Solver&amp;diff=17899"/>
		<updated>2006-10-03T19:06:53Z</updated>

		<summary type="html">&lt;p&gt;Tent: /* Non-Linear Programming (NLP) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The goal of this project is to develop a Calc add-on component that solves a constrained linear or non-linear programming model for an optimum solution.  An optimum solution in this case is defined as a feasible point that either maximizes or minimizes the objective function while satisfying all given constraints.&lt;br /&gt;
&lt;br /&gt;
This component is written in C++, so a good knowledge of C++ and design pattern helps tremendously if you want to hack at it.  Of course, at least a basic knowledge of operations research is a prerequisite, but you don&amp;#039;t necessarily need to be an expert to get involved.&lt;br /&gt;
&lt;br /&gt;
=Developer(s)=&lt;br /&gt;
* [[User:Kohei|Kohei Yoshida]] --- Original author, and current maintainer&lt;br /&gt;
* S. Sevki Dincer&lt;br /&gt;
* Jody Goldberg&lt;br /&gt;
* Michael Meeks&lt;br /&gt;
&lt;br /&gt;
Change log is [http://cvs.gnome.org/viewcvs/ooo-build/scratch/scsolver/ChangeLog?view=markup here].&lt;br /&gt;
&lt;br /&gt;
=Download and Test=&lt;br /&gt;
A binary snapshot is available on [http://kohei.us/ooo/solver/ Kohei Yoshida&amp;#039;s website].  Right now, the x86 Linux binary is actively maintained for each snapshot release, but Windows binary for the February 2006 snapshot is available thanks to Kami.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can download and install OpenSUSE 10.1 from the [http://www.opensuse.org/ OpenSUSE project website].  The edition of OO.o shipped with OpenSUSE 10.1 includes this Solver.&lt;br /&gt;
&lt;br /&gt;
To install, follow these steps (in English build):&lt;br /&gt;
&lt;br /&gt;
* Download the latest solver.uno.zip, but don&amp;#039;t unzip it.&lt;br /&gt;
* Open Calc, go to Tools - Package Manager.&lt;br /&gt;
* Select &amp;quot;My Packages&amp;quot;, and click &amp;quot;Add&amp;quot;.&lt;br /&gt;
* Locate that solver.uno.zip file you have downloaded, and hit OK to load it.&lt;br /&gt;
* Once Calc finishes registering the component, close all OO.o windows, and restart Calc.  You should then see a floating toolbar with the word &amp;quot;Solver&amp;quot; on it.&lt;br /&gt;
&lt;br /&gt;
= Hacking Solver =&lt;br /&gt;
The easiest way to get started is to download and compile [[ooo-build]] from CVS.  The Solver code can be found at &amp;lt;code&amp;gt;ooo-build/scratch/scsolver&amp;lt;/code&amp;gt;.  Build ooo-build normally as instructed in [[ooo-build]] page, and you should have a top level &amp;lt;code&amp;gt;scsolver&amp;lt;/code&amp;gt; module directory at &amp;lt;code&amp;gt;ooo-build/build/[upstream build name]/scsolver&amp;lt;/code&amp;gt;.  The upstream build name here refers to the name of a (semi-)latest milestone that the build script has downloaded for you when you ran &amp;lt;code&amp;gt;configure &amp;amp; download&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure ==&lt;br /&gt;
The &amp;lt;code&amp;gt;scsolver&amp;lt;/code&amp;gt; module is structured as follows:&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;idl&amp;#039;&amp;#039;&amp;#039; - IDL files for exported UNO interfaces.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;docs&amp;#039;&amp;#039;&amp;#039; - some, admittedly very outdated doc files.  The class diagram may be somewhat useful.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;prj&amp;#039;&amp;#039;&amp;#039; - contains files that are necessary for OO.o build process.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;source&amp;#039;&amp;#039;&amp;#039; - main source directory&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;inc&amp;#039;&amp;#039;&amp;#039; - headers&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;numeric&amp;#039;&amp;#039;&amp;#039; - numerical code (including optimization/matrix codes)&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;service&amp;#039;&amp;#039;&amp;#039; - UNO interface&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;ui&amp;#039;&amp;#039;&amp;#039; - UI code (uses UNO&amp;#039;s dialog framework - fairly rudimentary)&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;util&amp;#039;&amp;#039;&amp;#039; - ?&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;workben&amp;#039;&amp;#039;&amp;#039; - contains files that are not part of the build process i.e. test files, files for building a separate binary UNO package etc.&lt;br /&gt;
&lt;br /&gt;
The backend numerical codes are all found in &amp;lt;code&amp;gt;source/numeric&amp;lt;/code&amp;gt;, whereas all the UI related codes are found in &amp;lt;code&amp;gt;source/ui&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Exported UNO Interface ==&lt;br /&gt;
The &amp;lt;code&amp;gt;scsolver&amp;lt;/code&amp;gt; module introduces the following UNO services and interfaces (subject to change without notice):&lt;br /&gt;
&lt;br /&gt;
=== Service ===&lt;br /&gt;
* &amp;lt;code&amp;gt;org.openoffice.sc.solver.Solver&amp;lt;/code&amp;gt; - the main Solver component.&lt;br /&gt;
* &amp;lt;code&amp;gt;org.openoffice.sc.solver.LpModel&amp;lt;/code&amp;gt; - This service holds linear-programming model properties to be passed to a LP algorithm.&lt;br /&gt;
* &amp;lt;code&amp;gt;org.openoffice.sc.solver.LpSolve&amp;lt;/code&amp;gt; - This service exports the &amp;lt;code&amp;gt;lp_solve&amp;lt;/code&amp;gt; library for use by the main Solver component.&lt;br /&gt;
&lt;br /&gt;
=== Interface ===&lt;br /&gt;
* &amp;lt;code&amp;gt;org.openoffice.sc.solver.XLpAlgorithm&amp;lt;/code&amp;gt; - Interface for LP algorithm object.  Any third party LP library needs to export this interface for it to be callable from the main Solver framework.&lt;br /&gt;
* &amp;lt;code&amp;gt;org.openoffice.sc.solver.XLpModel&amp;lt;/code&amp;gt; - Interface for LP model.  An object that supports this interface can be passed onto another object of type &amp;lt;code&amp;gt;XLpAlgorithm&amp;lt;/code&amp;gt; to compute a solution.&lt;br /&gt;
&lt;br /&gt;
=== Enum ===&lt;br /&gt;
* &amp;lt;code&amp;gt;org.openoffice.sc.solver.Goal&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;MAXIMIZE&amp;lt;/code&amp;gt; maximize model&lt;br /&gt;
** &amp;lt;code&amp;gt;MINIMIZE&amp;lt;/code&amp;gt; minimize model&lt;br /&gt;
** &amp;lt;code&amp;gt;UNKNOWN&amp;lt;/code&amp;gt; goal unknown&lt;br /&gt;
* &amp;lt;code&amp;gt;org.openoffice.sc.solver.Bound&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;UPPER&amp;lt;/code&amp;gt; upper bound of a decision variable&lt;br /&gt;
** &amp;lt;code&amp;gt;LOWER&amp;lt;/code&amp;gt; lower bound of a decision variable&lt;br /&gt;
* &amp;lt;code&amp;gt;org.openoffice.sc.solver.Equality&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GREATER_EQUAL&amp;lt;/code&amp;gt; constraint &amp;gt;= rhs&lt;br /&gt;
** &amp;lt;code&amp;gt;EQUAL&amp;lt;/code&amp;gt; constraint = rhs&lt;br /&gt;
** &amp;lt;code&amp;gt;LESS_EQUAL&amp;lt;/code&amp;gt; constraint &amp;lt;= rhs&lt;br /&gt;
&lt;br /&gt;
Note that these interfaces may disappear as we are working toward eliminating the UNO glue layer to reduce run-time overhead.&lt;br /&gt;
&lt;br /&gt;
= Task Breakdown =&lt;br /&gt;
== Core Optimization Algorithms ==&lt;br /&gt;
&lt;br /&gt;
Listed below are algorithms proposed to be included in future versions of Calc Solver.  Some are being actively developed, while the others are still in planning.&lt;br /&gt;
&lt;br /&gt;
=== Linear Programming (LP) ===&lt;br /&gt;
With the exception of the Interior Point, much of linear programming will be delegated to the Simplex-based &amp;lt;code&amp;gt;lp_solve&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot; width=&amp;quot;100%&amp;quot;&lt;br /&gt;
!width=&amp;quot;40%&amp;quot;|Algorithm&lt;br /&gt;
!width=&amp;quot;30%&amp;quot;|Developer&lt;br /&gt;
!width=&amp;quot;15%&amp;quot;|Status&lt;br /&gt;
!width=&amp;quot;15%&amp;quot;|Date Finished&lt;br /&gt;
|-&lt;br /&gt;
|Revised Simplex Method&lt;br /&gt;
|Kohei Yoshida&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;finished&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|2006-03-16&lt;br /&gt;
|-&lt;br /&gt;
|Bounded Revised Simplex Method&lt;br /&gt;
|Kohei Yoshida&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;in progress&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|Interior Point Method&lt;br /&gt;
|&lt;br /&gt;
|proposed&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Mixed Integer Linear Programming (MILP) ===&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot; width=&amp;quot;100%&amp;quot;&lt;br /&gt;
!width=&amp;quot;40%&amp;quot;|Algorithm&lt;br /&gt;
!width=&amp;quot;30%&amp;quot;|Developer&lt;br /&gt;
!width=&amp;quot;15%&amp;quot;|Status&lt;br /&gt;
!width=&amp;quot;15%&amp;quot;|Date Finished&lt;br /&gt;
|-&lt;br /&gt;
|Branch and Bound&lt;br /&gt;
|&lt;br /&gt;
|&amp;lt;code&amp;gt;lp_solve&amp;lt;/code&amp;gt;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|Branch and Cut&lt;br /&gt;
|&lt;br /&gt;
|&amp;lt;code&amp;gt;lp_solve&amp;lt;/code&amp;gt; (?)&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Non-Linear Programming (NLP) ===&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot; width=&amp;quot;100%&amp;quot;&lt;br /&gt;
!width=&amp;quot;40%&amp;quot;|Algorithm&lt;br /&gt;
!width=&amp;quot;30%&amp;quot;|Developer&lt;br /&gt;
!width=&amp;quot;15%&amp;quot;|Status&lt;br /&gt;
!width=&amp;quot;15%&amp;quot;|Date Finished&lt;br /&gt;
|-&lt;br /&gt;
|Quasi-Newton Method with BFGS Update&lt;br /&gt;
|Kohei Yoshida&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;in progress&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|Adaptive Penalty Method&lt;br /&gt;
|&lt;br /&gt;
|in consideration&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|Generalized Reduced [http://grin-optics.org Gradient] (GRG) Method&lt;br /&gt;
|Leandro Silveira Monteiro da Silva&lt;br /&gt;
|proposed&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|Penalty Method&lt;br /&gt;
|&lt;br /&gt;
|proposed&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|Barrier Method&lt;br /&gt;
|&lt;br /&gt;
|proposed&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|Genetic Algorithm&lt;br /&gt;
|&lt;br /&gt;
|planned&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Mixed Integer Non-Linear Programming (MINLP) ===&lt;br /&gt;
* ?&lt;br /&gt;
&lt;br /&gt;
== Third Party Library Integration ==&lt;br /&gt;
&lt;br /&gt;
=== lp_solve ===&lt;br /&gt;
In a nutshell, [http://lpsolve.sourceforge.net/ lp_solve] is a Mixed Integer Linear Programming (MILP) solver supervised by Kjell Eikland and Peter Notebaert.  It is released under GPL/LGPL.  It provides the revised simplex method and the Branch-and-Bound method for solving pure LP and MILP.  The lp_solve project provides excellent documentation for [http://lpsolve.sourceforge.net/5.1/ v5.1 - stable branch] and [http://lpsolve.sourceforge.net/5.5/ v5.5 - latest branch].  The package can be downloaded from [http://sourceforge.net/projects/lpsolve/ here].&lt;br /&gt;
&lt;br /&gt;
There are two possible integration strategies.  In the first strategy, the algorithms provided by lp_solve is exported as UNO services in order to provide access for the current Calc Solver framework.  To make this happen, the lp_solve library needs to be modified into its own UNO component and be installed alongside the current core Solver component.  Since lp_solve itself is an external library i.e. a code that will not be submitted under [[JCA]], the modification made to lp_solve will also be treated as external code licensed under LGPL.  In the second strategy, Solver is simply dynamically linked to the lp_solve library, thus avoiding the overhead of UNO.&lt;br /&gt;
&lt;br /&gt;
On the main Solver component side, a new class will be created as a derived class of &amp;lt;code&amp;gt;numeric::opres::lp::BaseAlgorithm&amp;lt;/code&amp;gt;, and this new class will convert the model&amp;#039;s properties passed from the Solver dialog into a format that can be digested by lp_solve.  Once lp_solve reaches a solution, or decides that no solution exists, that result will be pushed back to the Solver component so that Solver can send the solution back to Calc, or displays an appropriate error message indicating no solution is found.&lt;br /&gt;
&lt;br /&gt;
==User Interface (UI)==&lt;br /&gt;
=== Disable cell updates during execution (Implemented --Kohei, 2006-6-20)===&lt;br /&gt;
During Solver&amp;#039;s execution, it modifies the values of those cells that are associated with a model so that the model defined as a set of formulas and numbers inside spreadsheet cells can be converted into the standard format of LP model.  It would be nice to disable cell updates during the solution-finding phase to prevent slowdown of the process.&lt;br /&gt;
&lt;br /&gt;
The implementation of this feature was fairly simple: just calling the &amp;lt;code&amp;gt;(un)lockControllers()&amp;lt;/code&amp;gt; method exported by the &amp;lt;code&amp;gt;XModel&amp;lt;/code&amp;gt; interface of the &amp;lt;code&amp;gt;SpreadsheetDocument&amp;lt;/code&amp;gt; object enables or disables cell updates.  Thanks to Niklas Nebel for giving me the tip.&lt;br /&gt;
&lt;br /&gt;
=== Immediate value as RHS of constraint (implemented --Kohei, 2006-06-18) ===&lt;br /&gt;
It is probably a standard behavior to allow a direct input of a value (i.e. &amp;lt;code&amp;gt;12.5&amp;lt;/code&amp;gt;) on the right hand side (RHS) of a constraint, instead of always requiring it to be a cell reference (i.e. &amp;lt;code&amp;gt;=$Sheet1.$A$5&amp;lt;/code&amp;gt;).  To implement this, an additional check needs to be put in place to see if a given input string is a valid 3D cell reference (sheet - column - row).  If the check fails, then we can try to convert the string into a double-precision and use it as the RHS value.  If even that conversion fails, then alert the user with an appropriate error message.&lt;br /&gt;
&lt;br /&gt;
The initial implementation of this feature is already in CVS.&lt;br /&gt;
&lt;br /&gt;
=== Automatic loading/saving of a model ===&lt;br /&gt;
Currently, loading and saving of a model to its associated document is done by storing the model information as a metadata of the document.  It may be useful to automate some of loading and saving of the model.&lt;br /&gt;
&lt;br /&gt;
=== Storing multiple models in a single document ===&lt;br /&gt;
Users often want to save multiple models into a single document, whereas currently one model can be saved per document.  It would be nice to add the capability of adding multiple models.  One way to implement this is to save the model data into a region of cells, which would allow storing as many models as the cells can hold in a single file.  It would also be nice to support saving and loading Excel Solver&amp;#039;s model format to allow migration from Excel Solver.&lt;br /&gt;
&lt;br /&gt;
Alternatively, we could also have multiple metadata entries with a nice front-end dialog to implement multiple model storage.  Which approach should be taken is subject to discussion.&lt;br /&gt;
&lt;br /&gt;
=== Options dialog ===&lt;br /&gt;
We need to create an options dialog to let user configure run-time behavior of the solver.  At a minimum, the following options need to be present:&lt;br /&gt;
&lt;br /&gt;
* algorithm type (LP, MILP, QP, NLP, ...)&lt;br /&gt;
* integer constraint&lt;br /&gt;
* positive variable constraint&lt;br /&gt;
&lt;br /&gt;
The options dialog should also have sensible default values since most users just want to run the solver, get the answer and move on.&lt;br /&gt;
&lt;br /&gt;
=== i18n ===&lt;br /&gt;
At a minimum, string l10n mechanism needs to be in place.  Work is in progress with Michael Meeks&amp;#039; help.&lt;br /&gt;
&lt;br /&gt;
=== User-defined Hessian matrix calculation ===&lt;br /&gt;
There are 3rd party high-performance [http://mathworld.wolfram.com/Hessian.html Hessian] matrix calculation program out there.  It would be nice to add a hook for such 3rd party software, so that the user can use it to speed up iteration.&lt;br /&gt;
&lt;br /&gt;
==Miscellaneous==&lt;br /&gt;
===Automatic Algorithm Selection===&lt;br /&gt;
We may need an optional mechanism to select appropriate optimization algorithms (LP vs QP, linear vs non-linear) based on the characteristics of a given model.  But such machanism should be optional so that the user can still pick and choose desired algorithms.&lt;br /&gt;
&lt;br /&gt;
===Decoupling of Algorithms and UI===&lt;br /&gt;
Eventually, the UI for Solver needs to be drawn by [[VCL]] to take advantage of VCL&amp;#039;s better widget controls over those of UNO&amp;#039;s.  To achieve this goal, the back-end algorithm framework needs to be exported as a UNO service independently of the UI.&lt;br /&gt;
&lt;br /&gt;
On the other hand, there is also a move to improve UNO AWT framework to support more widgets, and add i18n framework.  It may make sense to just extend our current UI, which is drawn by UNO AWT in order for us to reuse the work that has already been done.&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
* General user&amp;#039;s guide.&lt;br /&gt;
* How-to docs for adding a new algorithm with perhaps a skeleton code.&lt;br /&gt;
&lt;br /&gt;
=Resources=&lt;br /&gt;
==Third Party Library==&lt;br /&gt;
Use of a third party library is encouraged, as long as there is no licensing conflict with OpenOffice.org.  We cannot integrate GPL&amp;#039;ed code due to licensing incompatibility.  LGPL-licensed library can be used, as long as such library is de-coupled and completely isolated from the core component code.  BSD-licensed code can be used in a similar fashion, but due to its advertizing clause it cannot be used within the core component that needs to become a part of OO.o (Sun&amp;#039;s requirement?).  So, both LGPL and BSD codes must be completely decoupled from the core Solver code.&lt;br /&gt;
&lt;br /&gt;
TODO: How about CPL?  Does it pose any constraint as far as integration goes? --[[User:Kohei|Kohei]] 06:16, 25 April 2006 (CEST)&lt;br /&gt;
&lt;br /&gt;
If you know of any other third party libraries not listed here, feel free to add it below.&lt;br /&gt;
&lt;br /&gt;
;Free Software&lt;br /&gt;
*[http://www.gnu.org/software/glpk/glpk.html GLPK] (GPL)&lt;br /&gt;
*[http://sourceforge.net/projects/lpsolve lp_solve] (GPL/LGPL)&lt;br /&gt;
*[http://www.coin-or.org/index.html COIN-OR] (CPL)&lt;br /&gt;
*[http://www.scipy.org/SciPy SciPy] - Scientific Tools for Python released under BSD license.  Currently for Python only (?)&lt;br /&gt;
&lt;br /&gt;
;Commercial&lt;br /&gt;
*np_sol&lt;br /&gt;
*[http://www.ilog.com/products/cplex/ cplex]&lt;br /&gt;
*[http://lindo.com/products/api/dllm.html LINDO API]&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
* [http://kohei.us/ooo/solver/ Kohei Yoshida&amp;#039;s Solver Page]&lt;br /&gt;
* [http://www-fp.mcs.anl.gov/otc/Guide/index.html NEOS Guide]&lt;br /&gt;
* [http://support.microsoft.com/kb/q214115/ XL2000: Solver Uses Generalized Reduced Gradient Algorithm]&lt;br /&gt;
* Learn to program a simple calc [[SimpleCalcAddIn|Addin]] in C++&lt;br /&gt;
* Learn to program a calc [[CompleteAddIn|Addin]] in C++&lt;br /&gt;
[[Category:Calc issues]]&lt;/div&gt;</summary>
		<author><name>Tent</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Chart2&amp;diff=17897</id>
		<title>Chart2</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Chart2&amp;diff=17897"/>
		<updated>2006-10-03T18:45:28Z</updated>

		<summary type="html">&lt;p&gt;Tent: /* The type of the com.sun.star.drawing.BitmapTable */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;#039;&amp;#039;Chart2&amp;#039;&amp;#039; is a sub-project of the [http://graphics.openoffice.org/chart/chart.html OpenOffice.org Chart Project]. Our goal is to develop a new Chart component for (presumably) OOo 2.6.&lt;br /&gt;
&lt;br /&gt;
Charts are used for visualizing data sets from e.g. spreadsheets by two and three dimensional diagrams. There are a lot of different two- and three-dimensional chart types you can choose from. This page gathers information about the new chart implementation of OpenOffice.org. It is especially written to help new comers to the process of developping in the new OOo chart module.&lt;br /&gt;
&lt;br /&gt;
If you would like to participate, if you have comments or questions related to the chart you are welcome on the graphics mailinglists:  (users,dev,features,bugs,cvs)@graphics.openoffice.org. See also the section at the bottom of this page called [Some useful information].&lt;br /&gt;
&lt;br /&gt;
= Development in the New Chart =&lt;br /&gt;
&lt;br /&gt;
As the information on how to compile the new chart and on how to develop in this project have become quite lenghty, they can be found now on separate pages:&lt;br /&gt;
&lt;br /&gt;
* [[FAQ about Chart API Compatibility]] If you have problems with Macros or extensions that use the com.sun.star.chart API you may find answers or ask questions on this page.&lt;br /&gt;
* [[Compiling the new chart module]]&lt;br /&gt;
* [[Developing for the new chart module]]&lt;br /&gt;
&lt;br /&gt;
= Open Technical Issues in the New Chart =&lt;br /&gt;
&lt;br /&gt;
There still some architectural issues left that have to be solved. This section serves for showing those problems and showing the progress in finding solutions.&lt;br /&gt;
&lt;br /&gt;
== Application-Framework-Related Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Identify the XDataProvider reliably ===&lt;br /&gt;
&lt;br /&gt;
If the chart is embedded in a container document that provides the data for this chart, the chart contains range-strings at several places in its &amp;lt;tt&amp;gt;conten.xml&amp;lt;/tt&amp;gt; stream that are understood by the container, so that the data can be located there.  In Calc such a string would look like this: &amp;quot;Sheet1.A2:A7&amp;quot;. Such range-strings can appear in the chart:plot-area element of a chart or at a chart:series, chart:categories or chart:domain element.&lt;br /&gt;
&lt;br /&gt;
If a chart has its own data, this data is stored in a local table in the XML-file.  The mentioned range-strings are then of a similar form, with the fixed table-name &amp;quot;local_table&amp;quot;. But, the local table is also stored, as a kind of cache, if the data comes from outside. Therefore the existence of the local table does not imply that a chart has own data.&lt;br /&gt;
&lt;br /&gt;
So, neither the existence of local data, nor the existence of range-addresses (and even the content, considering that it is allowed that a sheet may also have the name local_table) determines whether or not a chart uses own data or data from the container document.&lt;br /&gt;
&lt;br /&gt;
In the old chart implementation, the chart always reads the internal data and uses it. If the data comes from the container, the container has an additional attribute that contains the complete data-range as one string. It then sets this string at the chart, which gives the chart the knowledge that data comes from outside (actually, in the old implementation, there is always local data. If data in Calc changes, the Calc prepares an SchMemChart object that contains the new local data and sets this object at the chart).&lt;br /&gt;
&lt;br /&gt;
In the new implementation, we must to get rid of the badly-designed approach, as we no longer have one complete address-range for the entire chart.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Solution&amp;lt;/b&amp;gt;: We have to introduce a new XML-attribute at the chart that identifies the data provider. This may be a flag denoting &amp;quot;own data&amp;quot; or &amp;quot;external data&amp;quot;, or even a URL, or the like, that uniquely identifies the data provider document.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Problem&amp;lt;/b&amp;gt;: Currently, it is necessary that when loading a chart, the container document is set as XParent before the chart itself is loaded. Otherwise there is no data provider, and the ranges are not valid for the internal data provider, and therefore are forgotten. A later setting of the data provider does not re-establish the correct range-strings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Update of the Chart on changed Data ===&lt;br /&gt;
&lt;br /&gt;
When a chart gets its data from the container document, and the data changes, the changes are notified via a listener mechanism. That is, when the chart queries for data at the XDataProvider, it gets XLabeledDataSequences. At those XLabeledDataSequences it starts listening for changes. If a change event is fired, the chart sets itself as modified, which forces the view to repaint, as it listens to model changes exactly via this mechanism.&lt;br /&gt;
&lt;br /&gt;
However, if a Calc document containing Charts is loaded, the charts are either not loaded immediately because they are not visible, or because the contain a replacement image that shows the last rendered view.&lt;br /&gt;
&lt;br /&gt;
In both cases, changes in the spreadsheet, like a change in data (which should be visible via a newly rendered view) or moving around ranges (which must change the ranges that are stored in the model), are not propagated to the chart, as it is not loaded and therefore is not listening.&lt;br /&gt;
&lt;br /&gt;
In the old implementation, again, the fact that the Calc knew the data-range for each chart, solved this problem. Because the Calc could load all unloaded charts affected by the change, and then notify it. However, this requires internal knowledge of the chart to be exposed to the container document.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;: When an OLE-object is loaded, it only shows the replacement image. This state is called the &amp;quot;LOADED&amp;quot; state. This means only a small &amp;quot;stub&amp;quot; is loaded, not the entire object. The XModel of an object (including the entirely applied content of the XML-streams) is loaded in the &amp;quot;RUNNING&amp;quot; state. So when all charts would initially be set into the RUNNING state, this would ensure the existence of all XModels, which would allow the listening to work.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;See also:&amp;#039;&amp;#039;&amp;#039; [[Chart2 Single-Click Concept]]. There, the issue of loading models at the right time is also handled.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Problem:&amp;#039;&amp;#039;&amp;#039;: It has to be evaluated, if loading the XModel objects of all charts in a document might take too long in loading a document, or if it consumes too much memory.&lt;br /&gt;
&lt;br /&gt;
=== Context Menus via Framework API ===&lt;br /&gt;
&lt;br /&gt;
The ChartController implements the XDispatchProvider that allows to find out whether menu entries are enabled or not via queryDispatch. The menu is created via an XML file that is defined in chart2/uiconfig.&lt;br /&gt;
&lt;br /&gt;
The content of the context menu, of course, depends on the context, so a generic mechanism (like an xml-file) for defining it may not always be possible, but in most cases is. Anyway, it should be possible to use context menus via UNO API, and also share the XDispatchProvider to find out if certain commands are available or not. Disabled menu items are not shown in context menus, but this should be handled by the implementation of the popup-menu.&lt;br /&gt;
&lt;br /&gt;
Currently, the menu shows icons next to some menu entries, but the context menu doesn&amp;#039;t. It should not be necessary to take care of the icons in the applications. They should work also via the framework.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution&amp;#039;&amp;#039;&amp;#039;: In the long run, the context menus should also be possible to create via xml-files. Maybe with the possibility to dynamically extend them with more entries (maybe needed for a list of corrections for auto-correction of mis-spelled words). As a short-term solution, there will be a function offered by the framework to pass an XPopupMenu and an XFrame which will take care of enabling commands via the dispatch found at the frame.&lt;br /&gt;
&lt;br /&gt;
=== Range Selection Component ===&lt;br /&gt;
&lt;br /&gt;
In the chart there is a dialog for assigning range-addresses to data series, categories or to the whole chart. The range-addresses must be in the correct format of the XDataProvider. Instead of typing tediously long and cryptic strings into the edit-field, a user rather wants to use the mouse (or keyboard) to select the ranges visually in the Calc.&lt;br /&gt;
&lt;br /&gt;
For this purpose the XDataProvider offers a method to retrieve a sheet.XRangeSelection via the getRangeSelection() method. This component provides a little dialog that contains the range-address and the possibility to select ranges with the mouse (which are then put into the dialog&amp;#039;s edit field). The content of the little dialog can be queried by the chart (which opened the range selection tool) and it can then put the string into the edit field in the chart&amp;#039;s own dialog.&lt;br /&gt;
&lt;br /&gt;
The problem here is, that charts are OLE-objects. The chart has to be in the UI_ACTIVE state to be able to open the dialog. When you press the button to open the range selection tool and click into the Calc spreadsheet, this action results in an automatic deactivation of the chart to the RUNNING state (which closes the dialog?) and activation of the Calc, which means the Calc is now UI_ACTIVE.&lt;br /&gt;
&lt;br /&gt;
To be UI_ACTIVE means also that the content of the menu bar as well as the existence and content of toolbars changes. In the case of the toolbars, this may also lead to a shift of the visual area of the document, and therefore a shift of the chart object.&lt;br /&gt;
&lt;br /&gt;
What we need here is a way to stay active in some sort in the chart (maybe ACTIVE instead of UI_ACTIVE) and be still able to select a range of cells in the Calc.&lt;br /&gt;
&lt;br /&gt;
== Calc- and Writer-Related Problems ==&lt;br /&gt;
&lt;br /&gt;
=== The com.sun.star.table.XTableCharts object is based on the old chart ===&lt;br /&gt;
&lt;br /&gt;
When you want to insert a new chart into Calc or Writer, this can be done via the com.sun.star.table.XTableChartSupplier interface that returns an XTableCharts container. At this container there is a method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void addNewByName(&lt;br /&gt;
   [in] string                            aName,&lt;br /&gt;
   [in] ::com::sun::star::awt::Rectangle  aRect,&lt;br /&gt;
   [in] sequence&amp;lt; CellRangeAddress &amp;gt;      aRanges,&lt;br /&gt;
   [in] boolean                           bColumnHeaders,&lt;br /&gt;
   [in] boolean                           bRowHeaders );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need a sequence of CellRangeAddresses to give a range and the parameters whether to use the first column or row for labels. In comparison to the XDataProvider method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
XDataSource createDataSource(&lt;br /&gt;
   [in] sequence&amp;lt; ::com::sun::star::beans::PropertyValue &amp;gt; aArguments );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the parameters in aArguments differ in the following way: instead of sequence&amp;lt; CellRangeAddress &amp;gt;, we only have one string. This is no problem, as there exists a conversion. But the parameter &amp;quot;DataRowSource&amp;quot; is missing. So you can only say if the first column or row is used for labels, but not if the data comes from rows or columns. Without this information, the other information is also useless. This renders the entire interface useless.&lt;br /&gt;
&lt;br /&gt;
As a work-around, you can create the chart with some dummy data, and then attach new data using the data provider interface. However, a new interface, probably one that only gets the name and the rectangle would be more appropriate than the work-around.&lt;br /&gt;
&lt;br /&gt;
=== Live-Preview when inserting a new Chart ===&lt;br /&gt;
&lt;br /&gt;
In the old implementation, when a chart was inserted into Calc or Writer, you got a dialog that had its own preview in a little window. After pressing OK, the chart was created and inserted into the document.&lt;br /&gt;
&lt;br /&gt;
In the new implementation, the container inserts a new chart first, then creates the wizard dialog (via UNO) and shows all changes directly in the newly inserted chart. When a user presses OK, everything is fine. But when a user presses Cancel, the inserted chart has to be removed again.&lt;br /&gt;
&lt;br /&gt;
This approach is new to the applications. You insert an object (modifying the document), change it, and after pressing Cancel, you might get the unmodified document without the chart you had before. Currently, the implementations create Undo-Actions for inserting a chart. After pressing Cancel, you might still have an Undo or Redo action to get the chart back. That is not what you would expect at this place, although the undo-action might be the correct object to use when you want to make the chart insertion undone. Maybe, it is sufficient here to remove the undo/redo action from the stack of the undo-manager.&lt;br /&gt;
&lt;br /&gt;
=== Drag &amp;amp;amp; Drop in Calc: Identify Drag-Source ===&lt;br /&gt;
&lt;br /&gt;
If you want to drag some selected cells in a spreadsheet and drop them on a chart, so that the chart uses this new data, the chart will get an XTransferable. The format that is contained in the XTransferable is currently the DDE format. The chart has to make sure that the dropped content comes from the same document or the same XDataProvider in particular. To do that, there must be a possibility to find out if an XTransferable belongs to the XParent of the current chart, or the XDataProvider which is attached.&lt;br /&gt;
&lt;br /&gt;
One idea was to compare the &amp;quot;Topic&amp;quot; part of the DDE message with the title of the Calc document&amp;#039;s window. Currently this is the same. At least during Drag &amp;amp;amp; Drop this should not change either. So, we would need a way to query the title of the parent XModel in exactly the format that is contained in the DDE topic (for an unsaved document the name is Untitled1, Untitled2, ...).&lt;br /&gt;
&lt;br /&gt;
Maybe there is a better approach. Something like&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; XDataProvider::isValidTransferable( [in] XTransferable xObject ) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This way, the data provider can implement what fits best to find out if the XTransferable comes from the same document.&lt;br /&gt;
&lt;br /&gt;
=== Drag &amp;amp;amp; Drop works only in ACTIVE mode ===&lt;br /&gt;
&lt;br /&gt;
Drag &amp;amp; Drop only works when the chart is always ACTIVE. So, unless charts will be always ACTIVE, drag &amp;amp;amp; drop does not work, as the drop target is not the chart but the surrounding embedded object. Alternatively, we need a mechanism that forwards the drop-request to the underlying OLE-object, which would require activation at least in this moment. This could be flag-driven, to avoid loading all OLE objects when hovering over them with drop content.&lt;br /&gt;
&lt;br /&gt;
== Graphic-Framework-Related Problems ==&lt;br /&gt;
&lt;br /&gt;
=== The type of the com.sun.star.drawing.BitmapTable ===&lt;br /&gt;
&lt;br /&gt;
For [http://grin-optics.org gradients], transparency-gradients, hatches, line-dashes and bitmaps there are tables in the chart model that contain those elements together with names. E.g., you may have a gradient with the name &amp;quot;My Gradient&amp;quot;. When you set the &amp;quot;FillGradientName&amp;quot; Property of an object to &amp;quot;My Gradient&amp;quot;, the object will display the corresponding gradient found in this table. The same holds for fill-bitmaps.&lt;br /&gt;
&lt;br /&gt;
However, there is a problem as the table for bitmaps maps a name to a URL rather than to some real graphic object. So, when you add an element to this table, the graphic itself isn&amp;#039;t used anywhere in the document at this time. As we have a graphic-manager that deals with all graphics, that keeps graphics only if they are used (if there is a refcount &amp;gt; 0), the grapghics are dropped in this case.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Solution&amp;lt;/b&amp;gt;: Change this map to a mapping from names (strings) to objects of type com.sun.star.graphic.XGraphic. As the existence of an XGraphic object ensures that the graphic is available in the graphic-manager, this will solve this problem. Only in the moment an element in this list is used in no model object and also removed from the list, the underlying graphic will be dropped by the graphic-manager.&lt;br /&gt;
&lt;br /&gt;
* see [http://www.openoffice.org/issues/show_bug.cgi?id=66558 Issue 66558]. Kai Ahrens works on this now. He will change the type of the bitmap table for all applications, as we now have the XGraphic API.&lt;br /&gt;
&lt;br /&gt;
== Chart Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Autoscaling of Text relative to Diagram Size ===&lt;br /&gt;
&lt;br /&gt;
In the old chart implementation, when auto-scaling was on, a resize of a chart OLE object or the resize of the Window of a standalone chart resulted in a resize of the actual font sizes in the model, i.e. the model was changed. In the case of an OLE object this is ok, as this also changes the visual area, which is also a model property. However, resizing a document window should not modify the model.&lt;br /&gt;
&lt;br /&gt;
To overcome this bad design, in the new chart we decided to add a reference size to font sizes in the model. So when auto-scaling should be on for an object, the size of the page (the whole chart, which equals the visual area size) is set as ReferencePageSize along with the font. So if the chart is resized, the view can calculate a new font size by comparing the new size of the page with this reference size and adapt the stored font size. So the font becomes bigger without having to change the model (apart from the fact that a resize of the OLE object modifies the model, because the visual area size is changed). If a font should not be scaled, the reference size is simply set to void. So far this concept is very good. It also solves the problem of getting the exact same font size after resizing the chart to an extreme (e.g. very small) and back to the original size again, which was a mess in the old chart.&lt;br /&gt;
&lt;br /&gt;
However, there are objects where the fonts are supposed to scale with the diagram size rather than the page size, e.g. the axes. The problem here is that the diagram size may be void, which means the view has to calculate it by itself. The actual size of the diagram is therefore not known unless a view is created that does the auto-calculation. So, if you want to enable auto-scaling for an axis in a chart, you would have to set the actual diagram size as refrerence size at the model axis object. However, you don&amp;#039;t know it when the diagram has an auto-size.&lt;br /&gt;
&lt;br /&gt;
In the file-format we should also have the currently visible font size plus a boolean flag saying whether an object should auto-scale or not. So, here we have a similar problem. We would need to have a view that calculates the size of the diagram (if it has auto-size), after a chart was loaded, in order to translate the boolean flag into a fitting diagram reference size. And also for saving, we would need the current diagram size for calculating the currently visible font size.&lt;br /&gt;
&lt;br /&gt;
So, for case that the diagram is auto-sized, to avoid having a view for switching auto-scale on for diagram-dependent font sizes, as well as saving and loading of files we need a solution here.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Solution ideas&amp;#039;&amp;#039;&amp;#039;:&lt;br /&gt;
&lt;br /&gt;
* In case the diagram is auto-sized, set the page size as reference size. Unless the diagram is resized, the mechanism would then work for resizes of the whole chart like before. The font size written to the file would be the real font size in the model, which is ok. The view would have to use the page size for comparison when it finds out that the diagram&amp;#039;s model has no size.&lt;br /&gt;
&lt;br /&gt;
* What happens if a user resizes the diagram? In this scenario we would need a mechanism that sets the currently calculated auto-size of the diagram (before the resize) as a fixed size to all model objects that use a diagram reference size and have the page size set as reference. Then it has to set the new diagram size at the diagram. This is error prone, as you might forget objects. Also, comparing the current reference size with the page size is also not very elegant.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Drop the feature of diagram-related font sizes.&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; Use only the page as reference size. This would simplify things but would break the feature of getting smaller fonts when you resize the diagram inside a chart document. I currently prefer this solution for different reasons.&lt;br /&gt;
** First, we only have one concept: a reference page size, not reference sizes that refer to different objects.&lt;br /&gt;
** Second, we always know the page size, as it is equal to the visual area size of the model. Apart from that an auto-page size wouldn&amp;#039;t make much sense. So, we solve this problem.&lt;br /&gt;
** Third, the down-side of doing this is, that resizing the diagram would not scale the fonts at axes, (axis titles?) and data points. But on the other hand, a chart document should layout the chart in a nice way, so that a user should not have the need to resize the diagram. If a user still wants to change the diagram size, he can change the font sizes manually. I think this is a valid compromise, as I think this does not happen too often. Also, for small diagram size changes a non-scaling font doesn&amp;#039;t matter too much.&lt;br /&gt;
** It simply does not make sense to set a reference size that is not found at the correspodning object (the diagram) in the model, but can only be obtained by a view. If you replaced your view implementation or you changed the auto-calculation of the view, you will get different results, so it is not reliable.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;On resize change the model.&amp;#039;&amp;#039;&lt;br /&gt;
** Setting re-scaled fonts is a bad idea as the old chart showed. You get rounding errors with sometimes drastic results.&lt;br /&gt;
** It would be ok for OLE objects, as they are modified anyway (the visual area size)&lt;br /&gt;
** If we would introduce a stand-alone chart some day, we would have to change the behaviour similar to draw or writer: The chart has a fixed page size and resizes of the window only change the visual area of the document. However, this conflicts with the use of the visual area as page size in the OLE scenario, where we definitely want to have the page size equal to the visual area size.&lt;br /&gt;
** Therefore, this is seems like a bad idea.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;Do not allow an empty diagram size if there are objects with DiagramReferenceSizes.&amp;#039;&amp;#039;&lt;br /&gt;
** This is also no good idea, as the diagram would need knowledge about all objects with diagram reference sizes, to behave accordingly on setting the size.&lt;br /&gt;
** When we want auto-resize as default, this would also mean the default would be to have a concrete diagram size, which is not reasonable.&lt;br /&gt;
&lt;br /&gt;
So, summarizing, dropping the feature of fonts scaling with the diagram seems the most appropriate thing to do. Of course we will lose a feature and have to decide if it is ok for users to no longer have this. As I said, I think resizing the diagram to something very much smaller than the one you get with auto-calculation is not a very common or typical scenario.&lt;br /&gt;
&lt;br /&gt;
(article by [[User:Bm@openoffice.org|Bm@openoffice.org]])&lt;br /&gt;
&lt;br /&gt;
= Documentation =&lt;br /&gt;
&lt;br /&gt;
= Some useful information =&lt;br /&gt;
&lt;br /&gt;
* Main Chart Project Page: http://graphics.openoffice.org/chart/chart.html&lt;br /&gt;
* Chart Specifications: http://specs.openoffice.org/chart/index.html&lt;br /&gt;
* Current CWS Name: [http://eis.services.openoffice.org/EIS2/cws.ShowCWS?Id=1074&amp;amp;Path=SRC680%2Fchart2mst3 chart2mst3]&lt;br /&gt;
* IRC channel: [irc://freenode/chart2.openoffice.org #chart2.openoffice.org] on freenode&lt;br /&gt;
* Björn&amp;#039;s [http://blogs.sun.com/bmilcke Weblog] (which also shows up at [http://planet.go-ooo.org/ Planet OpenOffice.org])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Calc issues]]&lt;br /&gt;
[[Category:Chart2]]&lt;br /&gt;
[[Category:Source_directories]]&lt;/div&gt;</summary>
		<author><name>Tent</name></author>
	</entry>
</feed>