Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
4568b088
Commit
4568b088
authored
Jun 29, 2015
by
Chinmay Garde
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
`Solver.flushParameterUpdates` returns the a collection of updated parameters
parent
df2eb202
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
14 deletions
+58
-14
param.dart
packages/cassowary/lib/param.dart
+7
-2
solver.dart
packages/cassowary/lib/solver.dart
+9
-5
variable.dart
packages/cassowary/lib/variable.dart
+7
-1
cassowary_test.dart
packages/cassowary/test/cassowary_test.dart
+35
-6
No files found.
packages/cassowary/lib/param.dart
View file @
4568b088
...
...
@@ -7,8 +7,13 @@ part of cassowary;
class
Param
extends
_EquationMember
{
final
Variable
variable
;
Param
.
withVariable
(
this
.
variable
);
Param
([
double
value
=
0.0
])
:
this
.
variable
=
new
Variable
(
value
);
Param
.
withVariable
(
this
.
variable
)
{
variable
.
_owner
=
this
;
}
Param
([
double
value
=
0.0
])
:
this
.
variable
=
new
Variable
(
value
)
{
variable
.
_owner
=
this
;
}
bool
get
isConstant
=>
false
;
...
...
packages/cassowary/lib/solver.dart
View file @
4568b088
...
...
@@ -168,16 +168,20 @@ class Solver {
return
_dualOptimize
();
}
void
flushVariableUpdates
()
{
List
<
Param
>
flushParameterUpdates
()
{
List
<
Param
>
updates
=
new
List
<
Param
>();
for
(
Variable
variable
in
_vars
.
keys
)
{
_Symbol
symbol
=
_vars
[
variable
];
_Row
row
=
_rows
[
symbol
];
if
(
row
==
null
)
{
variable
.
value
=
0.0
;
}
else
{
variable
.
value
=
row
.
constant
;
double
updatedValue
=
row
==
null
?
0.0
:
row
.
constant
;
if
(
variable
.
_applyUpdate
(
updatedValue
)
&&
variable
.
_owner
!=
null
)
{
updates
.
add
(
variable
.
_owner
);
}
}
return
updates
;
}
_Symbol
_symbolForVariable
(
Variable
variable
)
{
...
...
packages/cassowary/lib/variable.dart
View file @
4568b088
...
...
@@ -8,12 +8,18 @@ class Variable {
double
value
=
0.0
;
String
name
;
Param
_owner
;
int
_tick
;
static
int
_total
=
0
;
Variable
(
this
.
value
)
:
_tick
=
_total
++;
// TODO(csg): Add external variable update callbacks here
bool
_applyUpdate
(
double
updated
)
{
bool
res
=
updated
!=
value
;
value
=
updated
;
return
res
;
}
String
get
debugName
=>
_elvis
(
name
,
"variable
${_tick}
"
);
...
...
packages/cassowary/test/cassowary_test.dart
View file @
4568b088
...
...
@@ -427,7 +427,7 @@ void main() {
var
left
=
new
Param
(-
20.0
);
Solver
s
=
new
Solver
();
s
.
addConstraint
(
left
>=
CM
(
0.0
));
s
.
flush
Variable
Updates
();
s
.
flush
Parameter
Updates
();
expect
(
left
.
value
,
0.0
);
});
...
...
@@ -443,7 +443,7 @@ void main() {
expect
(
s
.
addConstraint
(
right
-
left
>=
CM
(
100.0
)),
Result
.
success
);
expect
(
s
.
addConstraint
(
left
>=
CM
(
0.0
)),
Result
.
success
);
s
.
flush
Variable
Updates
();
s
.
flush
Parameter
Updates
();
expect
(
left
.
value
,
0.0
);
expect
(
mid
.
value
,
50.0
);
...
...
@@ -484,7 +484,7 @@ void main() {
expect
(
s
.
addEditVariable
(
mid
.
variable
,
Priority
.
strong
),
Result
.
success
);
expect
(
s
.
suggestValueForVariable
(
mid
.
variable
,
300.0
),
Result
.
success
);
s
.
flush
Variable
Updates
();
s
.
flush
Parameter
Updates
();
expect
(
left
.
value
,
0.0
);
expect
(
mid
.
value
,
300.0
);
...
...
@@ -494,10 +494,14 @@ void main() {
test
(
'test_description'
,
()
{
var
left
=
new
Param
(
0.0
);
var
right
=
new
Param
(
100.0
);
var
c
=
right
>=
left
;
var
c1
=
right
>=
left
;
var
c2
=
right
<=
left
;
var
c3
=
(
right
==
left
)
as
Constraint
;
Solver
s
=
new
Solver
();
expect
(
s
.
addConstraint
(
c
),
Result
.
success
);
expect
(
s
.
addConstraint
(
c1
),
Result
.
success
);
expect
(
s
.
addConstraint
(
c2
),
Result
.
success
);
expect
(
s
.
addConstraint
(
c3
),
Result
.
success
);
expect
(
s
.
toString
()
!=
null
,
true
);
});
...
...
@@ -519,7 +523,7 @@ void main() {
solver
.
addConstraint
((
p2
==
CM
(
2.0
)
*
p1
)
as
Constraint
);
solver
.
addConstraint
((
container
==
(
p1
+
p2
+
p3
))
as
Constraint
);
solver
.
flush
Variable
Updates
();
solver
.
flush
Parameter
Updates
();
expect
(
container
.
value
,
100.0
);
...
...
@@ -527,4 +531,29 @@ void main() {
expect
(
p2
.
value
,
60.0
);
expect
(
p3
.
value
,
10.0
);
});
test
(
'test_updates_collection'
,
()
{
Param
left
=
new
Param
();
Param
mid
=
new
Param
();
Param
right
=
new
Param
();
Solver
s
=
new
Solver
();
expect
(
s
.
addEditVariable
(
mid
.
variable
,
Priority
.
strong
),
Result
.
success
);
expect
(
s
.
addConstraint
((
mid
*
CM
(
2.0
)
==
left
+
right
)
as
Constraint
),
Result
.
success
);
expect
(
s
.
addConstraint
(
left
>=
CM
(
0.0
)),
Result
.
success
);
expect
(
s
.
suggestValueForVariable
(
mid
.
variable
,
50.0
),
Result
.
success
);
var
updates
=
s
.
flushParameterUpdates
();
expect
(
updates
.
length
,
2
);
expect
(
updates
[
0
]
is
Param
,
true
);
expect
(
left
.
value
,
0.0
);
expect
(
mid
.
value
,
50.0
);
expect
(
right
.
value
,
100.0
);
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment