Mathematica, NMinimize extract data from list

In summary, the conversation is about a person struggling to use NMinimize in their model for goal programming. They are trying to extract a number from a matrix and use it in their objective function, but are encountering errors. They are seeking help with relating their satisfaction matrix to chosen shifts in order to maximize employee satisfaction while respecting certain constraints. The conversation suggests using a different function, First[Sort[vector,myShiftSortingFunction]], to find the preferable shift, and encourages the person to provide a clear description of their problem and data in a Mathematica notebook for others to help them more effectively.
  • #1
parzio
4
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
  • #2
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.
 
  • #3
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!
 
  • #4
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.
 
  • #5


I understand your struggle with NMinimize and extracting data from a list. Mathematica's NMinimize function is designed to find the minimum value of a given function, subject to certain constraints. In this case, it seems like you are trying to extract a specific value from a list using a variable, which may not be possible with NMinimize.

You may want to consider using the Part function in Mathematica to extract values from a list. For example, if you want to extract the first element from the first list in your matrix, you can use S[[1,1]]. This will return the value 5.

Furthermore, it is important to make sure that your constraints are valid when using NMinimize. In your case, it seems like the constraint involving the summation may be causing the error. Make sure that the indices used in your constraint are valid and that the constraint itself makes sense in the context of your problem.

I hope this helps and good luck with your model!
 

What is Mathematica?

Mathematica is a computational software program used for mathematical, scientific, and engineering calculations. It is known for its powerful functions and algorithms that allow for complex data analysis and visualization.

How does Mathematica handle data extraction?

Mathematica has built-in functions, such as NMinimize, that can extract data from lists by using various algorithms and methods, such as minimizing a function. It also has the ability to manipulate and organize data from various sources, making it a versatile tool for data extraction.

Can Mathematica extract data from large datasets?

Yes, Mathematica has the capability to handle large datasets and extract data efficiently. It can also parallelize computations to speed up the data extraction process.

Is Mathematica suitable for statistical analysis?

Yes, Mathematica has a wide range of statistical functions and packages that make it suitable for statistical analysis. It can perform various statistical tests, generate plots and charts, and visualize data in different ways.

Can Mathematica extract data from non-numerical lists?

Yes, Mathematica has functions that can extract data from non-numerical lists, such as strings or symbols. It also has the ability to convert non-numerical data into numerical data for further analysis.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • Programming and Computer Science
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
22
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • Electrical Engineering
Replies
1
Views
762
Back
Top