Mathematica Mathematica, NMinimize extract data from list

AI Thread Summary
The discussion revolves around challenges in using NMinimize in Mathematica for a goal programming model involving a satisfaction matrix. The initial problem involves extracting values from a matrix to construct an objective function and constraints, but errors arise due to incorrect specifications in the Extract function. A user seeks to maximize employee satisfaction based on a matrix that correlates employees to shifts, aiming to select optimal shifts over a month while adhering to constraints. Suggestions include simplifying the problem by focusing on sorting functions rather than directly using NMinimize, and emphasizing the need for clearer problem descriptions and structured data for effective assistance. The importance of providing complete examples and Mathematica notebooks for better support is also highlighted.
parzio
Messages
4
Reaction score
0
Hi guys,

I am struggling again NMinimize.

This is my problem:

I am creating a model by using goal programming, my problem now is given a list of list i.e a matrix defined in this way

S = {{5, 2, 7, 9}, {1, 2, 3, 4}, {3, 1, 2, 4}}

extract from the first list {5,2,7,9} a number by passing a variable in extract method.

I mean, this is my model:

NMinimize [{

n1+p1, (this is my objective function)
x1j == 2 (Now i am using a stupid number but this will be modified)
Ʃ Extract[Extract[S,1],x1j]+n1-p1 == 10, (The summation start from j=1 to 2)
n1>= 0,
p1>=0

},{x1j,n1,p1}]

In this case, on my side the result should be x11 = 5, x12 = 5, n1=0, p1=0, but unfortunately this not happen.

This error is launched:

Extract::psl: Position specification Subscript[x, 1,1] in Extract[{5,2,7,9},Subscript[x, 1,1]] is not an integer or a list of integers. >>
NMinimize::bcons: The constraints are not valid. >>

Someone can help me?

Thanks a lot!
 
Physics news on Phys.org
If you could stop writing things that are not Mathematica code and instead write a very simple understandable description of what you want to accomplish then it might be possible for someone to translate that into Mathematica for you.
 
I try to be more clear.

I have the following problem:

I have to maximize the satisfaction of an employee with respect to a certain shift in an certain day of a month. I have the matrix satisfaction (Employees,shifts) and is something like this: S= {{4,3,5,2},{3,4,5,1}} Each element represents the satisfaction of an employee with respect to a certain shift so employee 1 has satisfaction 4 with respect shift 1.

My model has to choose the right shift for all month days in order to maximize the employee satisfaction by respecting certain constraints.

My greatest problem is relate satisfaction matrix with chosen shift. I am not able to use in method NMaximize a function that takes the chosen shifts and employee and returns the satisfaction and so doing a summation over all month days. I need to maximize something like this:

Summation(from j=1 to j=31) getSatisfaction[1,chosenShift for that day)

Do you know how can I write this in mathematica? I am struggling to this problem for several days but I am not able to solve this problem. I need the input to relate chosen shift with satisfaction matrix.

Thanks a lot!
 
Try to forget for the moment that NMinimize exists, there is no such function. You perhaps cannot use NMinimize on functions in the way you think so this may be for the best.

Consider using instead First[Sort[vector,myShiftSortingFunction]]

To use this you must have two things.
1: a vector containing all the possible shifts, not a matrix.
2: define myShiftSortingFunction which is given two shifts and determines which of the two is preferable.

Here is an example:
In[1]:= shifts={{5,2,5,4},{2,5,2,8},{1,7,3,4},{4,5,6,2}};
myShiftSortingFunction[{s1_,s2_}]:=First[s1]<First[s2];
First[Sort[shifts,myShiftSortingFunction[{#1,#2}]&]]

Out[3]= {1,7,3,4}

That has found the shift with the smallest first element.
This is as if you were able to use NMinimize on a vector of shifts and find the shift with the smallest first value.
Make up some example vectors of shifts and see if you are able to use this to correctly extract shifts.

Clearly you will then want to do something more complicated than this. Perhaps you can use this idea to find what you need.

If not then try to describe your problem even more clearly. Describe what data you have in what structure. Describe what conditions you need to enforce. Give a complete example and what the result should be and why.

Attach all that to a post as a simple Mathematica notebook. Most others do not want to type back in your notebook from an image to try to test their code on your data.
 

Similar threads

Replies
6
Views
4K
Replies
1
Views
3K
Replies
5
Views
2K
Replies
2
Views
3K
Replies
22
Views
3K
Replies
6
Views
2K
Replies
1
Views
4K
Back
Top