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
d4a67499
Commit
d4a67499
authored
Jun 25, 2015
by
Chinmay Garde
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement Solver.suggestValue
parent
436f272a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
2 deletions
+91
-2
solver.dart
packages/cassowary/lib/solver.dart
+91
-2
No files found.
packages/cassowary/lib/solver.dart
View file @
d4a67499
...
...
@@ -130,8 +130,14 @@ class Solver {
return
_edits
.
containsKey
(
variable
);
}
Result
suggestVariable
(
Variable
v
,
double
value
)
{
return
Result
.
unimplemented
;
Result
suggestValueForVariable
(
Variable
variable
,
double
value
)
{
if
(!
_edits
.
containsKey
(
variable
))
{
return
Result
.
unknownEditVariable
;
}
_suggestValueForEditInfoWithoutDualOptimization
(
_edits
[
variable
],
value
);
return
_dualOptimize
();
}
void
updateVariable
()
{}
...
...
@@ -426,6 +432,89 @@ class Solver {
}
return
third
;
}
void
_suggestValueForEditInfoWithoutDualOptimization
(
EditInfo
info
,
double
value
)
{
double
delta
=
value
-
info
.
constant
;
info
.
constant
=
value
;
{
Symbol
symbol
=
info
.
tag
.
marker
;
Row
row
=
_rows
[
info
.
tag
.
marker
];
if
(
row
!=
null
)
{
if
(
row
.
add
(-
delta
)
<
0.0
)
{
_infeasibleRows
.
add
(
symbol
);
}
return
;
}
symbol
=
info
.
tag
.
other
;
row
=
_rows
[
info
.
tag
.
other
];
if
(
row
!=
null
)
{
if
(
row
.
add
(
delta
)
<
0.0
)
{
_infeasibleRows
.
add
(
symbol
);
}
return
;
}
}
for
(
Symbol
symbol
in
_rows
.
keys
)
{
Row
row
=
_rows
[
symbol
];
double
coeff
=
row
.
coefficientForSymbol
(
info
.
tag
.
marker
);
if
(
coeff
!=
0.0
&&
row
.
add
(
delta
*
coeff
)
<
0.0
&&
symbol
.
type
!=
SymbolType
.
external
)
{
_infeasibleRows
.
add
(
symbol
);
}
}
}
Result
_dualOptimize
()
{
while
(
_infeasibleRows
.
length
!=
0
)
{
Symbol
leaving
=
_infeasibleRows
.
removeLast
();
Row
row
=
_rows
[
leaving
];
if
(
row
!=
null
&&
row
.
constant
<
0.0
)
{
Symbol
entering
=
_getDualEnteringSymbolForRow
(
row
);
if
(
entering
.
type
==
SymbolType
.
invalid
)
{
return
Result
.
internalSolverError
;
}
_rows
.
remove
(
leaving
);
row
.
solveForSymbols
(
leaving
,
entering
);
_substitute
(
entering
,
row
);
_rows
[
entering
]
=
row
;
}
}
return
Result
.
success
;
}
Symbol
_getDualEnteringSymbolForRow
(
Row
row
)
{
Symbol
entering
;
double
ratio
=
double
.
MAX_FINITE
;
Map
<
Symbol
,
double
>
rowCells
=
row
.
cells
;
for
(
Symbol
symbol
in
rowCells
.
keys
)
{
double
value
=
rowCells
[
symbol
];
if
(
value
>
0.0
&&
symbol
.
type
!=
SymbolType
.
dummy
)
{
double
coeff
=
_objective
.
coefficientForSymbol
(
symbol
);
double
r
=
coeff
/
value
;
if
(
r
<
ratio
)
{
ratio
=
r
;
entering
=
symbol
;
}
}
}
return
_elvis
(
entering
,
new
Symbol
(
SymbolType
.
invalid
,
0
));
}
}
class
Tag
{
...
...
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