Confronting dates in a constrain
古いコメントを表示
I am implementing an optimisation problem on matlab and one of the constraints imposes an inequality of the type: date(x) * decision variable> date(y) + duration
Obviously I cannot multiply a date by a number so how could I solve the problem?
Thanks in advance for the help!
回答 (1 件)
Walter Roberson
2024 年 2 月 26 日
移動済み: Walter Roberson
2024 年 2 月 26 日
Perhaps
decision_variable * (date(x) > date(y) + duration)
leading to
date(y) - date(x) + duration
multiplied by something. But the something is not necessarily the decision variable: it depends on what the intent is when the decision variable is false, whether that is intended to cause the constraint to pass or to fail.
5 件のコメント
Erika
2024 年 2 月 26 日
Eric Sofen
2024 年 2 月 27 日
編集済み: Eric Sofen
2024 年 2 月 28 日
Notice that:
- datenum is marked "not recommended" in the documentation. It is an old function with various shortcomings and has been replaced with datetime. We discourage users from using datenum in new code unless there's a particularly compelling reason (and then we want to hear about why datetime doesn't work for that particular situation, so we can improve it).
- datenum represents the number of days since the year 0 CE. Does multiplying that time period by decision_variable really make sense for solving your problem? Because of this, Walter's suggested approach seems more fruitful.
datenum() represents the number of days since year 0 Common Era
datenum('jan 1 1970')
datestr(0)
Erika
2024 年 2 月 28 日
Eric Sofen
2024 年 2 月 28 日
@Walter Roberson, whoops! Of course, you're right about the epoch for datenum. I went back and edited my post.
カテゴリ
ヘルプ センター および File Exchange で Time Series Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!