Mathematica, NMinimize extract data from list

  • Context: Mathematica 
  • Thread starter Thread starter parzio
  • Start date Start date
  • Tags Tags
    Data List Mathematica
Click For Summary

Discussion Overview

The discussion revolves around the use of Mathematica's NMinimize and NMaximize functions for optimization problems involving matrices. Participants are exploring how to extract data from lists and relate satisfaction matrices to chosen shifts for maximizing employee satisfaction under certain constraints.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes a problem with using NMinimize, specifically regarding the extraction of elements from a list and the resulting error messages encountered.
  • Another participant suggests that the original poster should clarify their goals in simpler terms rather than presenting Mathematica code directly.
  • A later reply proposes an alternative approach to the problem by suggesting the use of sorting functions instead of NMinimize, emphasizing the need for a vector of shifts rather than a matrix.
  • There is a suggestion to define a sorting function to compare shifts based on specific criteria, which may help in extracting the desired shifts.
  • Participants express the need for clearer descriptions of the data structures and constraints involved in the optimization problem.

Areas of Agreement / Disagreement

Participants do not appear to reach a consensus on the best approach to solve the optimization problem. Multiple competing views remain regarding the use of NMinimize versus alternative methods, and the discussion remains unresolved.

Contextual Notes

Limitations include unclear definitions of the data structures and constraints, as well as unresolved issues regarding the application of NMinimize and NMaximize functions in the context described.

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 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K