Hi
tuple t_job {
string grp;
int id;
int sz;
};
{t_job} Jobs = {
<"A", 1, 60>,
<"A", 2, 10>,
<"A", 3, 14>,
<"B", 4, 39>,
<"B", 5, 78>
};
{string} grps={i.grp | i in Jobs};
{int} idsPerGrp[g in grps]={i.id| i in Jobs:i.grp==g};
tuple t_batch {
string grp;
{int} id_list;
int sz;
};
{t_batch} batch =
{ <j.grp, idsPerGrp[j.grp],sum(j2 in Jobs: j2.grp==j.grp) j2.sz >| j in Jobs};
execute {
writeln(batch);
}
gives
{<"A" {1 2 3} 84> <"B" {4 5} 117>}
regards
PS
Many how to with OPL in https://www.linkedin.com/pulse/how-opl-alex-fleischer/
------------------------------
[Alex] [Fleischer]
[EMEA CPLEX Optimization Technical Sales]
[IBM]
------------------------------
Original Message:
Sent: Thu February 18, 2021 11:23 AM
From: Andy Ham
Subject: Script to concatenate members into a set
I would like to generate an output like this:
{<"A" {1,2,3} 84>
<"B" {4,5}, 117>}
by using the following script.
We can sum up values, but I don't know how to concatenate values. Can you please help me? Also, it will be very appreciated if I can hear any advice on overlap and non-overlap at the same sequence. Thanks,
tuple t_job {
string grp;
int id;
int sz;
};
{t_job} Jobs = {
<"A", 1, 60>,
<"A", 2, 10>,
<"A", 3, 14>,
<"B", 4, 39>,
<"B", 5, 78>
};
tuple t_batch {
string grp;
// {int} id_list;
int sz;
}; {t_batch} batch =
{ <j.grp, sum(j2 in Jobs: j2.grp==j.grp) j2.sz >| j in Jobs};
execute {
writeln(batch);
}
------------------------------
Andy Ham
------------------------------
#DecisionOptimization