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
704d0174
Commit
704d0174
authored
Jun 30, 2015
by
Chinmay Garde
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Solver.flush update returns the set of context associated with parameters in play
parent
4568b088
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
14 deletions
+47
-14
param.dart
packages/cassowary/lib/param.dart
+7
-2
solver.dart
packages/cassowary/lib/solver.dart
+8
-3
cassowary_test.dart
packages/cassowary/test/cassowary_test.dart
+32
-9
No files found.
packages/cassowary/lib/param.dart
View file @
704d0174
...
...
@@ -6,12 +6,17 @@ part of cassowary;
class
Param
extends
_EquationMember
{
final
Variable
variable
;
final
dynamic
context
;
Param
.
withVariable
(
this
.
variable
)
{
Param
([
double
value
=
0.0
])
:
variable
=
new
Variable
(
value
),
context
=
null
{
variable
.
_owner
=
this
;
}
Param
([
double
value
=
0.0
])
:
this
.
variable
=
new
Variable
(
value
)
{
Param
.
withContext
(
ctx
)
:
variable
=
new
Variable
(
0.0
),
context
=
ctx
{
variable
.
_owner
=
this
;
}
...
...
packages/cassowary/lib/solver.dart
View file @
704d0174
...
...
@@ -168,8 +168,8 @@ class Solver {
return
_dualOptimize
();
}
List
<
Param
>
flushParameter
Updates
()
{
List
<
Param
>
updates
=
new
List
<
Param
>
();
Set
flush
Updates
()
{
Set
updates
=
new
Set
();
for
(
Variable
variable
in
_vars
.
keys
)
{
_Symbol
symbol
=
_vars
[
variable
];
...
...
@@ -178,9 +178,14 @@ class Solver {
double
updatedValue
=
row
==
null
?
0.0
:
row
.
constant
;
if
(
variable
.
_applyUpdate
(
updatedValue
)
&&
variable
.
_owner
!=
null
)
{
updates
.
add
(
variable
.
_owner
);
dynamic
context
=
variable
.
_owner
.
context
;
if
(
context
!=
null
)
{
updates
.
add
(
context
);
}
}
}
return
updates
;
}
...
...
packages/cassowary/test/cassowary_test.dart
View file @
704d0174
...
...
@@ -427,7 +427,7 @@ void main() {
var
left
=
new
Param
(-
20.0
);
Solver
s
=
new
Solver
();
s
.
addConstraint
(
left
>=
CM
(
0.0
));
s
.
flush
Parameter
Updates
();
s
.
flushUpdates
();
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
Parameter
Updates
();
s
.
flushUpdates
();
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
Parameter
Updates
();
s
.
flushUpdates
();
expect
(
left
.
value
,
0.0
);
expect
(
mid
.
value
,
300.0
);
...
...
@@ -523,7 +523,7 @@ void main() {
solver
.
addConstraint
((
p2
==
CM
(
2.0
)
*
p1
)
as
Constraint
);
solver
.
addConstraint
((
container
==
(
p1
+
p2
+
p3
))
as
Constraint
);
solver
.
flush
Parameter
Updates
();
solver
.
flushUpdates
();
expect
(
container
.
value
,
100.0
);
...
...
@@ -533,9 +533,9 @@ void main() {
});
test
(
'test_updates_collection'
,
()
{
Param
left
=
new
Param
(
);
Param
mid
=
new
Param
(
);
Param
right
=
new
Param
(
);
Param
left
=
new
Param
.
withContext
(
"left"
);
Param
mid
=
new
Param
.
withContext
(
"mid"
);
Param
right
=
new
Param
.
withContext
(
"right"
);
Solver
s
=
new
Solver
();
...
...
@@ -547,13 +547,36 @@ void main() {
expect
(
s
.
suggestValueForVariable
(
mid
.
variable
,
50.0
),
Result
.
success
);
var
updates
=
s
.
flush
Parameter
Updates
();
var
updates
=
s
.
flushUpdates
();
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
);
});
test
(
'test_updates_collection_is_set'
,
()
{
Param
left
=
new
Param
.
withContext
(
"a"
);
Param
mid
=
new
Param
.
withContext
(
"a"
);
Param
right
=
new
Param
.
withContext
(
"a"
);
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
(
10.0
)),
Result
.
success
);
expect
(
s
.
suggestValueForVariable
(
mid
.
variable
,
50.0
),
Result
.
success
);
var
updates
=
s
.
flushUpdates
();
expect
(
updates
.
length
,
1
);
expect
(
left
.
value
,
10.0
);
expect
(
mid
.
value
,
50.0
);
expect
(
right
.
value
,
90.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