Carl Love

Carl Love

26513 Reputation

25 Badges

11 years, 190 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@RukevweOyinloye Yes, that's what I thought: that something was missing. Yet I'm certain that my code has the same mathematical information as your code (same objective and constraints); I just made it linear. But I realize that neither of these codes captures the essence of your verbal description of the problem. Can you formulate algebraically some constraints to capture the role of groups? Perhaps you meant for the "... = 1" on the constraints to be attached to the inner add, thus making 6 constraints in this case rather than 3?

Please also see the similar Reply that I posted in the subthread under the main Question a few minutes ago.

I notice from both your code and text that the "profiles" are partitioned into "groups", and also that the number of groups is irrelevant to this code because each constraint is simply the sum of a complete column of the decision-variable matrix X equated to 1. So, do you think that you need more constraints tthat use the groups?

Is there any real-world reason why the groups would be the same size? It would very easy to recode this so that the groups could be an arbitrary partition of the profiles rather than a partition into equal size blocks.

@acer It seems quite odd to me that indets is "smart enough" to avoid returning bound variables from RootOf, yet it doesn't do it for Int, int, Sum, sum, or any other standard command with a bound variable that I can find. The bound variables of ints and sums are often automatically generated by dsolve and other commands. One often sees _a_k1, etc.

Do you have any idea why indets gives special treatment to RootOf like this?

I've long thought that symbolic computation needs a formal way to declare a variable as bound.  

@TKChang99 The syntax Surface(...certainly makes it seem as if Surface is a separate command (with its own help page) rather than simply an option to SurfaceInt, so it's no surprise that there was that confusion. The standard syntax for an option would be Surface= [...], and I can't see any good reason why the integration commands in VectorCalculus couldn't use this more-standard syntax.

@RukevweOyinloye Here is a more-streamlined version of code that does exactly the same thing. While writing this code, I noticed that num_groups is irrelevant for this presumably toy example. Either I'm missing something, or its relevance won't become apparent until the example is more complicated.

restart
:

num_profiles:= 4:  num_websites:= 3:
X:= Matrix((num_profiles, num_websites), symbol= x);
objs:= seq(ArrayTools:-AddAlongDimension(X,2)):
'objs' = <objs>;
constraints:=
    seq(ArrayTools:-AddAlongDimension(X,1)) =~ 1,
    z >=~ objs
:
'constraints' = <constraints>;
sol:= Optimization:-Minimize(
    z, {constraints}, integervariables= {z}, binaryvariables= {seq}(X)
);
optimal_assignment:= eval(X, sol[2]);
for ij in op(2, optimal_assignment) do
    printf("Profile %d assigned to Website %d.\n", lhs(ij))
od;
printf("Objective Value (Minimized Maximum Website Overlap): %d.\n", sol[1]);

Matrix(4, 3, {(1, 1) = x[1, 1], (1, 2) = x[1, 2], (1, 3) = x[1, 3], (2, 1) = x[2, 1], (2, 2) = x[2, 2], (2, 3) = x[2, 3], (3, 1) = x[3, 1], (3, 2) = x[3, 2], (3, 3) = x[3, 3], (4, 1) = x[4, 1], (4, 2) = x[4, 2], (4, 3) = x[4, 3]})

objs = (Vector(4, {(1) = x[1, 1]+x[1, 2]+x[1, 3], (2) = x[2, 1]+x[2, 2]+x[2, 3], (3) = x[3, 1]+x[3, 2]+x[3, 3], (4) = x[4, 1]+x[4, 2]+x[4, 3]}))

constraints = (Vector(7, {(1) = x[1, 1]+x[2, 1]+x[3, 1]+x[4, 1] = 1, (2) = x[1, 2]+x[2, 2]+x[3, 2]+x[4, 2] = 1, (3) = x[1, 3]+x[2, 3]+x[3, 3]+x[4, 3] = 1, (4) = x[1, 1]+x[1, 2]+x[1, 3] <= z, (5) = x[2, 1]+x[2, 2]+x[2, 3] <= z, (6) = x[3, 1]+x[3, 2]+x[3, 3] <= z, (7) = x[4, 1]+x[4, 2]+x[4, 3] <= z}))

sol := [1, [z = 1, x[1, 1] = 0, x[1, 2] = 0, x[1, 3] = 0, x[2, 1] = 0, x[2, 2] = 1, x[2, 3] = 0, x[3, 1] = 0, x[3, 2] = 0, x[3, 3] = 1, x[4, 1] = 1, x[4, 2] = 0, x[4, 3] = 0]]

Matrix(%id = 36893490538334837084)

Profile 2 assigned to Website 2.
Profile 3 assigned to Website 3.
Profile 4 assigned to Website 1.
Objective Value (Minimized Maximum Website Overlap): 1.

NULL

Download firstworkablecode.mw

@mmcdara X is the array of binary decision variables such that X[i,j] = 1 iff profile i should be assigned to website j. It shouldn't have a numeric datatype.

@RukevweOyinloye One thing that you certainly must do is remove the minimize from the objective function. The Optimization[Minimize] already specifies that you want to minimize.

You probably have other problems also, which'll be easier to diagnose when you upload a worksheet.

@nm That _Z is the bound variable of RootOf​​​​​, and every RootOf has a _Z, so you'd might as well just filter out all occurences of RootOf. That _Z is very different from the free variables returned by discontsolve, etc., that you're otherwise looking for.

@Carl Love Some commands may also return unknown functions, such as _F(x, y). For example, pdsolve might do this. These can be filtered by type typefunc(suffixed('_')) as the 2nd indets argument. To filter both symbols and functions, make the type 

{thistype, typefunc}(suffixed('_'))

To filter indexed names as well, make it

{thistype, typefunc, typeindex}(suffixed('_'))

@Thomas Dean You can use until testeq(...)=FAIL instead of the overly complicated 
until evalb(testeq(...)=FAIL).

@Thomas Dean Sorry, you were right; there is a difference. I think that the presence of a difference in how while and until handle FAIL should be considered a bug in the implementation of until.

@Thomas Dean There is no difference in how ifwhile, and until interpret FAIL! They all interpret it the same as false.

@Preben Alsholm You can also do

TypeTools:-AddType(ID, ()-> try type(args) catch: false end try);

@tim_finks Sorry that I didn't notice that this was about Maple Flow instead of Maple.

@nm Yes, you're right about numelems. I'll correct the Answer. I did know this, but I was momentarily fooled by the coincidence of both values being 3. Thank you for spotting that.

First 7 8 9 10 11 12 13 Last Page 9 of 689