~jozilla/uiml.net/uiml.net-tp

« back to all changes in this revision

Viewing changes to Cassowary/ClLinearInequality.cs

  • Committer: Jo Vermeulen
  • Date: 2007-09-05 14:26:30 UTC
  • mfrom: (249.1.16 Uiml.net)
  • Revision ID: jo.vermeulen@uhasselt.be-20070905142630-w5eafpsfntbgz0ko
Merged with Jo's main branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  Cassowary.net: an incremental constraint solver for .NET
3
 
  (http://lumumba.uhasselt.be/jo/projects/cassowary.net/)
4
 
  
5
 
  Copyright (C) 2005  Jo Vermeulen (jo.vermeulen@uhasselt.be)
6
 
  
7
 
  This program is free software; you can redistribute it and/or
8
 
  modify it under the terms of the GNU Lesser General Public License
9
 
  as published by the Free Software Foundation; either version 2.1
10
 
  of  the License, or (at your option) any later version.
11
 
 
12
 
  This program is distributed in the hope that it will be useful,
13
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
  GNU Lesser General Public License for more details.
16
 
 
17
 
  You should have received a copy of the GNU Lesser General Public License
18
 
  along with this program; if not, write to the Free Software
19
 
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
 
*/
21
 
 
22
 
using System;
23
 
 
24
 
namespace Cassowary
25
 
{
26
 
  public class ClLinearInequality : ClLinearConstraint
27
 
  {
28
 
    public ClLinearInequality(ClLinearExpression cle,
29
 
                              ClStrength strength,
30
 
                              double weight) : base(cle, strength, weight)
31
 
    {}
32
 
 
33
 
    public ClLinearInequality(ClLinearExpression cle,
34
 
                              ClStrength strength) : base(cle, strength)
35
 
    {}
36
 
 
37
 
    public ClLinearInequality(ClLinearExpression cle) : base(cle)
38
 
    {}
39
 
 
40
 
    public ClLinearInequality(ClVariable clv1,
41
 
                              byte op_enum,
42
 
                              ClVariable clv2,
43
 
                              ClStrength strength,
44
 
                              double weight) : base(new ClLinearExpression(clv2), strength, weight)
45
 
                              /* throws ExClInternalError */
46
 
    {
47
 
      switch (op_enum)
48
 
      {
49
 
        case Cl.GEQ:
50
 
          _expression.MultiplyMe(-1.0);
51
 
          _expression.AddVariable(clv1);
52
 
          break;
53
 
        case Cl.LEQ:
54
 
          _expression.AddVariable(clv1, -1.0);
55
 
          break;
56
 
        default:
57
 
          // invalid operator
58
 
          throw new ExClInternalError("Invalid operator in ClLinearInequality constructor");
59
 
      }
60
 
    }
61
 
 
62
 
    public ClLinearInequality(ClVariable clv1,
63
 
                              byte op_enum,
64
 
                              ClVariable clv2,
65
 
                              ClStrength strength) : this(clv1, op_enum, clv2, strength, 1.0)
66
 
                              /* throws ExClInternalError */
67
 
    {}
68
 
 
69
 
    public ClLinearInequality(ClVariable clv1,
70
 
                              byte op_enum,
71
 
                              ClVariable clv2) : this(clv1, op_enum, clv2, ClStrength.Required, 1.0)
72
 
                              /* throws ExClInternalError */
73
 
    {}
74
 
 
75
 
    public ClLinearInequality(ClVariable clv,
76
 
                              byte op_enum,
77
 
                              double val,
78
 
                              ClStrength strength,
79
 
                              double weight) : base(new ClLinearExpression(val), strength, weight)
80
 
                              /* throws ExClInternalError */
81
 
    {
82
 
      switch (op_enum)
83
 
      {
84
 
        case Cl.GEQ:
85
 
          _expression.MultiplyMe(-1.0);
86
 
          _expression.AddVariable(clv);
87
 
          break;
88
 
        case Cl.LEQ:
89
 
          _expression.AddVariable(clv, -1.0);
90
 
          break;
91
 
        default:
92
 
          // invalid operator
93
 
          throw new ExClInternalError("Invalid operator in ClLinearInequality constructor");
94
 
      }
95
 
    }
96
 
 
97
 
    public ClLinearInequality(ClVariable clv,
98
 
                              byte op_enum,
99
 
                              double val,
100
 
                              ClStrength strength) : this(clv, op_enum, val, strength, 1.0)
101
 
                              /* throws ExClInternalError */
102
 
    {}
103
 
 
104
 
    public ClLinearInequality(ClVariable clv,
105
 
                              byte op_enum,
106
 
                              double val) : this(clv, op_enum, val, ClStrength.Required, 1.0)
107
 
                              /* throws ExClInternalError */
108
 
    {}
109
 
 
110
 
    public ClLinearInequality(ClLinearExpression cle1,
111
 
                              byte op_enum,
112
 
                              ClLinearExpression cle2,
113
 
                              ClStrength strength,
114
 
                              double weight) : base((ClLinearExpression) cle2.Clone(), strength, weight)
115
 
                              /* throws ExClInternalError */
116
 
    {
117
 
      switch (op_enum)
118
 
      {
119
 
        case Cl.GEQ:
120
 
          _expression.MultiplyMe(-1.0);
121
 
          _expression.AddExpression(cle1);
122
 
          break;
123
 
        case Cl.LEQ:
124
 
          _expression.AddExpression(cle1, -1.0);
125
 
          break;
126
 
        default:
127
 
          // invalid operator
128
 
          throw new ExClInternalError("Invalid operator in ClLinearInequality constructor");
129
 
      }
130
 
    }
131
 
 
132
 
    public ClLinearInequality(ClLinearExpression cle1,
133
 
                              byte op_enum,
134
 
                              ClLinearExpression cle2,
135
 
                              ClStrength strength) : this(cle1, op_enum, cle2, strength, 1.0)
136
 
                              /* throws ExClInternalError */
137
 
    {}
138
 
 
139
 
    public ClLinearInequality(ClLinearExpression cle1,
140
 
                              byte op_enum,
141
 
                              ClLinearExpression cle2) : this(cle1, op_enum, cle2, ClStrength.Required, 1.0)
142
 
                              /* throws ExClInternalError */
143
 
    {}
144
 
 
145
 
    public ClLinearInequality(ClAbstractVariable clv,
146
 
                              byte op_enum,
147
 
                              ClLinearExpression cle,
148
 
                              ClStrength strength,
149
 
                              double weight) : base((ClLinearExpression) cle.Clone(), strength, weight)
150
 
                              /* throws ExClInternalError */
151
 
    {
152
 
      switch (op_enum)
153
 
      {
154
 
        case Cl.GEQ:
155
 
          _expression.MultiplyMe(-1.0);
156
 
          _expression.AddVariable(clv);
157
 
          break;
158
 
        case Cl.LEQ:
159
 
          _expression.AddVariable(clv, -1.0);
160
 
          break;
161
 
        default:
162
 
          // invalid operator
163
 
          throw new ExClInternalError("Invalid operator in ClLinearInequality constructor");
164
 
      }
165
 
    }
166
 
 
167
 
    public ClLinearInequality(ClAbstractVariable clv,
168
 
                              byte op_enum,
169
 
                              ClLinearExpression cle,
170
 
                              ClStrength strength) : this(clv, op_enum, cle, strength, 1.0)
171
 
                              /* throws ExClInternalError */
172
 
    {}
173
 
 
174
 
    public ClLinearInequality(ClAbstractVariable clv,
175
 
                              byte op_enum,
176
 
                              ClLinearExpression cle) : this(clv, op_enum, cle, ClStrength.Required, 1.0)
177
 
                              /* throws ExClInternalError */
178
 
    {}
179
 
 
180
 
    public ClLinearInequality(ClLinearExpression cle,
181
 
                              byte op_enum,
182
 
                              ClAbstractVariable clv,
183
 
                              ClStrength strength,
184
 
                              double weight) : base((ClLinearExpression) cle.Clone(), strength, weight)
185
 
                              /* throws ExClInternalError */
186
 
    {
187
 
      switch (op_enum)
188
 
      {
189
 
        case Cl.LEQ:
190
 
          _expression.MultiplyMe(-1.0);
191
 
          _expression.AddVariable(clv);
192
 
          break;
193
 
        case Cl.GEQ:
194
 
          _expression.AddVariable(clv, -1.0);
195
 
          break;
196
 
        default:
197
 
          // invalid operator
198
 
          throw new ExClInternalError("Invalid operator in ClLinearInequality constructor");
199
 
      }
200
 
    }
201
 
 
202
 
    public ClLinearInequality(ClLinearExpression cle,
203
 
                              byte op_enum,
204
 
                              ClAbstractVariable clv,
205
 
                              ClStrength strength) : this(cle, op_enum, clv, strength, 1.0)
206
 
                              /* throws ExClInternalError */
207
 
    {}
208
 
 
209
 
    public ClLinearInequality(ClLinearExpression cle,
210
 
                              byte op_enum,
211
 
                              ClAbstractVariable clv) : this(cle, op_enum, clv, ClStrength.Required, 1.0)
212
 
                              /* throws ExClInternalError */
213
 
    {}
214
 
 
215
 
    public sealed override bool IsInequality
216
 
    {
217
 
      get { return true; }
218
 
    }
219
 
 
220
 
    public sealed override string ToString()
221
 
    {
222
 
      return base.ToString() + " >= 0)";
223
 
    }
224
 
  }
225
 
}