1/*
2 * Copyright 2007, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5#ifndef LAYOUT_OPTIMIZER_H
6#define LAYOUT_OPTIMIZER_H
7
8#include <List.h>
9#include <math.h>
10
11#include "LinearSpec.h"
12
13
14static const double kEqualsEpsilon = 0.000001;
15
16
17double** allocate_matrix(int m, int n);
18void free_matrix(double** matrix);
19void copy_matrix(const double* const* A, double** B, int m, int n);
20void zero_matrix(double** A, int m, int n);
21int compute_dependencies(double** a, int m, int n, bool* independent);
22
23
24bool is_soft(Constraint* constraint);
25
26
27class LayoutOptimizer {
28public:
29								LayoutOptimizer(const ConstraintList& list,
30									int32 variableCount);
31								~LayoutOptimizer();
32
33			bool				SetConstraints(const ConstraintList& list,
34									int32 variableCount);
35
36			status_t			InitCheck() const;
37
38			bool				Solve(double* initialSolution);
39
40private:
41			double				_ActualValue(Constraint* constraint,
42									double* values) const;
43			double				_RightSide(Constraint* constraint);
44
45			void				_MakeEmpty();
46			void				_Init(int32 variableCount, int32 nConstraints);
47
48			bool				_Solve(double* values);
49			bool				_SolveSubProblem(const double* d, int am,
50									double* p);
51			void				_SetResult(const double* x, double* values);
52
53
54			int32				fVariableCount;
55			ConstraintList*		fConstraints;
56
57			double**			fTemp1;
58			double**			fTemp2;
59			double**			fZtrans;
60			double**			fQ;
61			double**			fActiveMatrix;
62			double**			fActiveMatrixTemp;
63			double**			fSoftConstraints;
64			double**			fG;
65			double*				fDesired;
66};
67
68
69inline bool
70fuzzy_equals(double a, double b)
71{
72	return fabs(a - b) < kEqualsEpsilon;
73}
74
75
76#endif	// LAYOUT_OPTIMIZER_H
77