te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>How to use arg_sort on a 'array[int] of var set of int' in Minizinc? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to use arg_sort on a 'array[int] of var set of int' in Minizinc? - Stack Overflow

programmeradmin6浏览0评论

Here is a small model that I have. I'm trying to solve it with Chuffed. There are a lot more constraints and variables to my problem, but I tried to single out what is not working.

% Model parameters.
int: n_steps;               % Number of steps in the scheduling horizon
enum tasks;                 % Set of all task ids
enum work_centers;          % Set of all work center ids

% task_work_center[t] is the work center required to do task t
array [tasks] of work_centers: task_work_center; 

% Model variables.
% task_start[t] is the starting step of task t
array [tasks] of var 1..n_steps: task_start ::add_to_output;

% Constraints.
% Example : array[1..n] of set of int: x = [ {k | k in sum([s[j]  | j in 1..i-1])+1..sum([s[j]  | j in 1..i]) } | i in 1..n];
array[work_centers] of var set of 1..n_steps: work_center_tasks = [{task_start[t] | t in tasks where task_work_center[t]==wc} | wc in work_centers];
array[work_centers] of var int: task_permutation;

include "arg_sort.mzn";
constraint
    forall(wc in work_centers)(
        task_permutation[wc] = arg_sort(work_center_tasks[wc])  %%% Does NOT work !!!
    );

% Objective.
solve satisfy;

I get the following error :

MiniZinc: type error: no function or predicate with this signature found: `arg_sort(var set of int)' Cannot use the following functions or predicates with the same identifier: function array [int] of $$E : arg_sort(array [$$E] of $$T: x); (argument 1 expects type array[int] of int, but type var set of int given) function array [int] of var $$E : arg_sort(array [$$E] of var $$T: x); (argument 1 expects type array[int] of var int, but type var set of int given) function array [int] of $$E : arg_sort(array [$$E] of float: x); (argument 1 expects type array[int] of float, but type var set of int given) function array [int] of var $$E : arg_sort(array [$$E] of var float: x); (argument 1 expects type array[int] of var float, but type var set of int given) predicate arg_sort(array [$$E] of var $$T: x,array [int] of var $$E: p); (requires 2 arguments, but 1 given) predicate arg_sort(array [$$E] of var float: x,array [int] of var $$E: p); (requires 2 arguments, but 1 given)

Do you guys know of a way to do this ? It seems like arg_sort cannot be used on var set of int... I don't mind using another method.

Edit/Adding information : I actually know in advance the dimensions of work_center_tasks, but it varies from one work center to another. If I can model that without using sets, that would work too !

Here is a small model that I have. I'm trying to solve it with Chuffed. There are a lot more constraints and variables to my problem, but I tried to single out what is not working.

% Model parameters.
int: n_steps;               % Number of steps in the scheduling horizon
enum tasks;                 % Set of all task ids
enum work_centers;          % Set of all work center ids

% task_work_center[t] is the work center required to do task t
array [tasks] of work_centers: task_work_center; 

% Model variables.
% task_start[t] is the starting step of task t
array [tasks] of var 1..n_steps: task_start ::add_to_output;

% Constraints.
% Example : array[1..n] of set of int: x = [ {k | k in sum([s[j]  | j in 1..i-1])+1..sum([s[j]  | j in 1..i]) } | i in 1..n];
array[work_centers] of var set of 1..n_steps: work_center_tasks = [{task_start[t] | t in tasks where task_work_center[t]==wc} | wc in work_centers];
array[work_centers] of var int: task_permutation;

include "arg_sort.mzn";
constraint
    forall(wc in work_centers)(
        task_permutation[wc] = arg_sort(work_center_tasks[wc])  %%% Does NOT work !!!
    );

% Objective.
solve satisfy;

I get the following error :

MiniZinc: type error: no function or predicate with this signature found: `arg_sort(var set of int)' Cannot use the following functions or predicates with the same identifier: function array [int] of $$E : arg_sort(array [$$E] of $$T: x); (argument 1 expects type array[int] of int, but type var set of int given) function array [int] of var $$E : arg_sort(array [$$E] of var $$T: x); (argument 1 expects type array[int] of var int, but type var set of int given) function array [int] of $$E : arg_sort(array [$$E] of float: x); (argument 1 expects type array[int] of float, but type var set of int given) function array [int] of var $$E : arg_sort(array [$$E] of var float: x); (argument 1 expects type array[int] of var float, but type var set of int given) predicate arg_sort(array [$$E] of var $$T: x,array [int] of var $$E: p); (requires 2 arguments, but 1 given) predicate arg_sort(array [$$E] of var float: x,array [int] of var $$E: p); (requires 2 arguments, but 1 given)

Do you guys know of a way to do this ? It seems like arg_sort cannot be used on var set of int... I don't mind using another method.

Edit/Adding information : I actually know in advance the dimensions of work_center_tasks, but it varies from one work center to another. If I can model that without using sets, that would work too !

Share Improve this question edited yesterday Emilie Picard-Cantin asked yesterday Emilie Picard-CantinEmilie Picard-Cantin 2903 silver badges15 bronze badges 1
  • Please comment on what you expect ⁣arg_sort(work_center_tasks[wc]) to do. It seems you are trying to call arg_sort on a var set of int, which doesn't seem to make sense because the element of the set are unordered, and it is defined that iterating over the set will always be ordered in MiniZinc. – Dekker1 Commented 9 hours ago
Add a comment  | 

1 Answer 1

Reset to default 0

Yes, it seems that fzn_arg_sort_set.mzn is not defined in minizinc standard library.

发布评论

评论列表(0)

  1. 暂无评论