{"action":"created","issue":{"url":"https://api.github.com/repos/ocaml/opam/issues/2109","labels_url":"https://api.github.com/repos/ocaml/opam/issues/2109/labels{/name}","comments_url":"https://api.github.com/repos/ocaml/opam/issues/2109/comments","events_url":"https://api.github.com/repos/ocaml/opam/issues/2109/events","html_url":"https://github.com/ocaml/opam/issues/2109","id":68358848,"number":2109,"title":"Adding support for \"as fresh as possible\" installations","user":{"login":"rdicosmo","id":687807,"avatar_url":"https://avatars.githubusercontent.com/u/687807?v=3","gravatar_id":"","url":"https://api.github.com/users/rdicosmo","html_url":"https://github.com/rdicosmo","followers_url":"https://api.github.com/users/rdicosmo/followers","following_url":"https://api.github.com/users/rdicosmo/following{/other_user}","gists_url":"https://api.github.com/users/rdicosmo/gists{/gist_id}","starred_url":"https://api.github.com/users/rdicosmo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rdicosmo/subscriptions","organizations_url":"https://api.github.com/users/rdicosmo/orgs","repos_url":"https://api.github.com/users/rdicosmo/repos","events_url":"https://api.github.com/users/rdicosmo/events{/privacy}","received_events_url":"https://api.github.com/users/rdicosmo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-04-14T12:37:03Z","updated_at":"2015-04-15T06:35:17Z","closed_at":null,"body":"The current implementation of opam, when calling the external solver, is unable to obtain solutions that give preference to fresher packages (it only supports, using the -notuptodate measure, giving preference to the latest version). This issue is raised again and again all over the place, see #2108 and #1897.\r\n\r\nIt is pretty easy to give priority to fresher versions when the latest is impossible to install, with no changes to the solver, as follows:\r\n\r\n   - for each package, add in the generated CUDF an integer field\r\n         penalty: \r\n     with value equal to the number of versions it lags behind the latest one available\r\n  \r\n    For example, if package foo has version 3.1 4.2 5.6 and 5.7, then 3.1 has penalty 3,\r\n    4.2 has penalty 2, 5.6 has penalty 1 and 5.7 has penalty 0\r\n\r\n  - add the user preference \"-sum(solution, penalty)\" when calling the solver\r\n\r\nand that will do it ... of course, on the academic side, we know this will not be \"perfect\" in all cases, but in practice it will make a hell of a difference.\r\n\r\nA side note, as always: there are no \"quirks\" in the external solvers.... aspcud/packup and the like *really* return a solution that is optimal according to the criteria passed to them. The issue is to find the right criteria/preferences to obtain what we have in mind :-)\r\n"},"comment":{"url":"https://api.github.com/repos/ocaml/opam/issues/comments/93218574","html_url":"https://github.com/ocaml/opam/issues/2109#issuecomment-93218574","issue_url":"https://api.github.com/repos/ocaml/opam/issues/2109","id":93218574,"user":{"login":"AltGr","id":807966,"avatar_url":"https://avatars.githubusercontent.com/u/807966?v=3","gravatar_id":"","url":"https://api.github.com/users/AltGr","html_url":"https://github.com/AltGr","followers_url":"https://api.github.com/users/AltGr/followers","following_url":"https://api.github.com/users/AltGr/following{/other_user}","gists_url":"https://api.github.com/users/AltGr/gists{/gist_id}","starred_url":"https://api.github.com/users/AltGr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AltGr/subscriptions","organizations_url":"https://api.github.com/users/AltGr/orgs","repos_url":"https://api.github.com/users/AltGr/repos","events_url":"https://api.github.com/users/AltGr/events{/privacy}","received_events_url":"https://api.github.com/users/AltGr/received_events","type":"User","site_admin":false},"created_at":"2015-04-15T06:35:17Z","updated_at":"2015-04-15T06:35:17Z","body":"Done! Quite straight-forward :)\r\n\r\nNote that I took a conservative approach in the default solver criteria: I kept the `-notuptodate` in front of the `-sum(version-lag)`, so it should really only change anything in the problematic cases we had. The criteria list is starting to get a bit too long though:\r\n```\r\nlet default_criteria_latest = {\r\n  crit_default = \"-count(removed),\\\r\n                  -notuptodate(request),-sum(request,version-lag),\\\r\n                  -count(down),\\\r\n                  -notuptodate(changed),-count(changed),\\\r\n                  -notuptodate(solution),-sum(solution,version-lag)\";\r\n  crit_upgrade = \"-count(down),\\\r\n                  -count(removed),\\\r\n                  -notuptodate(solution),-sum(solution,version-lag),\\\r\n                  -count(new)\";\r\n  crit_fixup = \"-count(changed),\\\r\n                -notuptodate(solution),-sum(solution,version-lag)\";\r\n}\r\n```"}}