Skip to content

wip: attempt fixing infinite loop#24

Draft
j-g00da wants to merge 1 commit intoratatui:mainfrom
j-g00da:js/cycle-prevention
Draft

wip: attempt fixing infinite loop#24
j-g00da wants to merge 1 commit intoratatui:mainfrom
j-g00da:js/cycle-prevention

Conversation

@j-g00da
Copy link
Member

@j-g00da j-g00da commented Jul 22, 2025

Resolves #18

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.60%. Comparing base (cf8c01f) to head (dd15b39).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #24      +/-   ##
==========================================
+ Coverage   76.24%   77.60%   +1.36%     
==========================================
  Files           8        8              
  Lines        1229     1259      +30     
==========================================
+ Hits          937      977      +40     
+ Misses        292      282      -10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


[dev-dependencies]
rstest = "0.25"
itertools = "0.14.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
itertools = "0.14.0"
itertools = "0.14"

Comment on lines +33 to +36

pub fn id(&self) -> usize {
self.0
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Symbol is an internal type, so you might instead just make it a struct with named fields - this is a non-breaking change. Though it sort of implies that id is mutable. That said, not a big deal. Whatever makes sense on this.

Comment on lines +656 to +667
let mut entering = Symbol::invalid();
let mut min_id = usize::MAX;

for (symbol, value) in &objective.cells {
if symbol.kind() != SymbolKind::Dummy && *value < 0.0 {
return *symbol;
if symbol.id() < min_id {
min_id = symbol.id();
entering = *symbol;
}
}
}
Symbol::invalid()
entering
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this use min_by_key. E.g. something like:

Suggested change
let mut entering = Symbol::invalid();
let mut min_id = usize::MAX;
for (symbol, value) in &objective.cells {
if symbol.kind() != SymbolKind::Dummy && *value < 0.0 {
return *symbol;
if symbol.id() < min_id {
min_id = symbol.id();
entering = *symbol;
}
}
}
Symbol::invalid()
entering
objective.cells
.iter()
.filter(|(symbol, value)| symbol.kind() != SymbolKind::Dummy && *value < 0.0)
.min_by_key(|(symbol, _)| symbol.id())
.unwrap_or(Symbol::invalid())

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably yes, this is a dirty branch, I'm just exploring what works at this moment so I want to keep the changes minimal.

@joshka
Copy link
Member

joshka commented Jul 22, 2025

Naive question (without looking at the details of the actual code): is there a reason why the values that are being searched can't be kept in symbol id order and then the first element is the one returned always?

@j-g00da
Copy link
Member Author

j-g00da commented Jul 23, 2025

Naive question (without looking at the details of the actual code): is there a reason why the values that are being searched can't be kept in symbol id order and then the first element is the one returned always?

That will be the next thing I check as it seems the best option to have this sorted already (store in minheap maybe?), but I finished testing this at 1AM yesterday and needed some sleep. Will get back to this when I have some more time.

@j-g00da
Copy link
Member Author

j-g00da commented Jul 23, 2025

I will also try applying ratatui/ratatui#1855 (comment) to kasuari. Thanks @Teufelchen1 for your work that led to this discovery! I don't see a reason why using a deterministic hasher here would be a problem, and this intuitively makes sense why it would fix the issue (but I would want to get deeper into that in free time to better understand what is happening).

As a side note there is a high potential for some optimizations on ratatui side. Even after fixing this, the time complexity for that is quite bad. We can apply some optimizations for e.g. cases like layouts using only Fill - this can be calculated without using the solver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolver hangs on certain condition

3 participants