Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arg_max for 2d arrays? #871

Closed
artsiomkaltovich opened this issue Dec 20, 2024 · 1 comment
Closed

arg_max for 2d arrays? #871

artsiomkaltovich opened this issue Dec 20, 2024 · 1 comment
Labels

Comments

@artsiomkaltovich
Copy link

First of all, I apologize if this should be an issue for the libminizinc project or if it shouldn’t be an issue at all.

What does $$E mean in the following code?

function $$E: arg_max(array [$$E] of bool: x)
function $$E: arg_max(array [$$E] of int: x)
function $$E: arg_max(array [$$E] of float: x)

Is it possible to use arg_max for 2D arrays or arrays with higher dimensions? Could you provide a working example of how to use it?

Thank you in advance.

@cyderize cyderize transferred this issue from MiniZinc/MiniZincIDE Jan 14, 2025
@Dekker1
Copy link
Member

Dekker1 commented Jan 14, 2025

In the function declarations you state, $$E would be a type-inst variable that (because of the double dollar signs) can be instated with enumerated types or just integers. In this case this ensures that if a enumerated type is used to form the index set of the argument for arg_max, then the returned value is also of that enumerated type (and not just an int).

Creating a version of arg_max that works for higher dimensions is certainly possible. A decomposition can be created using the 1d version of arg_max and an element constraint:

function var tuple($$E, $$F): arg_max(array[$$E, $$F] of var int: x) = let {
	any: idxs = [(i, j) | i in index_set_1of2(x), j in index_set_2of2(x)];
	any: sel = arg_max(array1d(x));
} in idxs[sel];

Note that it seems that the any type doesn't work for idxs in the current release. You instead can use the array[int] of tuple(int, int) for idxs, although it is technically not fully correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants