Teep

135 Reputation

5 Badges

12 years, 80 days

MaplePrimes Activity


These are replies submitted by Teep

@Markiyan Hirnyk 

Hi Markiyan.

I like that ...!

The function in question, L(z), is the standard loss function and comprises both the density and distribution functions of the standard normal distribution.There are tables of L(z) values readily available given (for instance) z in the range [-3,3].

Given a known L value, I was seeking to extract the associated z-value and our friend has successfully supplied a routine to do just that. 

I hope that clarifies matters.

@vv

Perfect .... this addresses the problem. Nice routine.

The numerical results align to the tabulated values.

 

Thanks so much. 

@Markiyan Hirnyk 

Now, that's efficiency!

I'm obliged .... thanks.

@Kitonum 

I'm very grateful .... thank you!

@gkokovidis 

Many thanks, Georgios ... much appreciated!

@tomleslie 

Thank you for clearing this up .... I appreciate your help.

@mehdi jafari 

 

That's great! I appreciate it ...

Thanks for this. 

However, I initially used that command and am still receiving an error message. As follows ...

Error, invalid input: rand expects its first argument, r,  to be of the type {posint, integer..integer} but received -.5 .. .5

@tomleslie 

Thanks .... I guessed so.

Thanks for that .... it works fine!

@Kitonum 

That works fine .... thank you!

@Thomas Richard 

That matches my result ... thanks, Thomas.

The equation structure is rather mis-leading (at least to me), so you've clarified my thinking here.

I appreciate it.

@Thomas Richard 

I appreciate the response, Thomas. Thanks.

However, that routine returns L := [d[0]*x[i, 0, 1]+d[0]*x[i, 1, 1]+d[1]*x[i, 0, 1]+d[1]*x[i, 1, 1], d[0]*x[i, 0, 2]+d[0]*x[i, 1, 2]+d[1]*x[i, 0, 2]+d[1]*x[i, 1, 2]].

As you can see, the values, i=0 and i=1 are not carried through to the full series; we only receive unknown terms, for instance x[i, 1,2] and so on. This is what I am trying to protect against. As the equation is stated, one would think that your routine would work ... but you see the problem. If we then take the values i=0 and i=1, then we will obtain two sequences ... however, I need to be sure.

Any other suggestions?


 

 

Constraint Problem

 

Given the sets:

• 

C = {1,2, ..., n}

• 

K = {1,2, ...., m}

• 

Arcs, A ={i,j},  representing connections between locations, i and j. For each arc, (i,j), i≠j, i≠n+1 and j≠0.

 

For each arc, {i,j}, i≠j, there are two matrices namely c[i, j]  and t[i, j] and for each point, i, there is a specified positive quantity, " d[i]."

Further, we impose a positive integer value on "q and fix a positive value to the parameter, S[j,k ]"NULL

There are two decision variables under consideration; one of which is binary.

• 

"s[i,k ] and "

• 

x[i, j, k] " = 1,  if  k  moves from vertex  i to  j; 0, otherwise."

 

"We seek to minimize  the function, z, where: "

" z=(∑)  (∑)  (∑)c[i,j]  x[i,j,k]"

 

subject to the constraints

NULL

"(i)    (∑)  (∑)x[i,j,k ] =1,           ∀i in C"

 

"(ii)  (&sum;)d[i ]  (&sum;)()[ ]x[i,j,k ]<=   q,    &forall;k in K"

 

"(iii)    (&sum;)x[0,j,k ] = 1,   &forall; k in K"

 

"(iv)    (&sum;)x[i,h,k ] - (&sum;)x[h, j,k ]= 0,    &forall; h in C,  &forall; k in K"

 

"(v)    (&sum;)x[i, n+1,  k ] = 1,    &forall; k in K"

NULLNULL

 

(vi)  "s[i,k]+ t[i,j]-K ( 1-  x[i,j, k]  ) <=  S[j,k] ,      &forall;i, j  in N,  &forall; k in K"

 

 

(vii)  "a[i]  <=  s[i,k] <=  b[i] ,         &forall; i in N,  &forall; k in K"

 

 

(viii)  "x[i, j, k ]  in {0,1}, " " &forall;i, j  in N,  &forall; k in K"

 

 

restart; with(Optimization)

 

 

The following model values are set-up for simplicity.

 

 

m := 1:

The values for "c[i,j ]and t[i,j ]are taken to be:"

c[0, 0] := 0:

t[0, 0] := 0:

S[j, k]*values*are

S[0, 0] := 0:

The vector, d[i]:

d[1] := 10000:

The quantitity q:

q := 2000:

The objective function:

z := add(add(add(c[i, j]*x[i, j, k], j = 0 .. n), i = 0 .. n), k = 1 .. m):

Constraint (1)

constraint1 := {seq(add(add(x[i, j, k], j = 0 .. n), k = 1 .. m) = 1, i = 1 .. n)}:

2*Constraint

constraint2 := expand({seq(add(d[i]*add(x[i, j, k], j = 0 .. n), i = 1 .. n) >= q, k = 1 .. m)}):

3*Constraint

constraint3 := {seq(add(x[0, j, k], j = 0 .. n) = 1, k = 1 .. m)}:

4*Constraint

constraint4 := {seq(seq(add(x[i, h, k], i = 0 .. n)-add(x[h, j, k], j = 0 .. n) = 0, h = 1 .. n), k = 1 .. m)}:

5*Constraint

constraint5 := {seq(add(x[i, n+1, k], i = 0 .. n) = 1, k = 1 .. m)}:

6*Constraint

e[1] := 1:

constraint6 := {seq(seq(seq(s[i, k]+t[i, j]-(l[i]+t[i, j]-e[j])*(1-x[i, j, k]) <= S[j, k], i = 1 .. n), j = 1 .. n), k = 1 .. m)}:

Constraint (7)

c3 := {seq(seq(e[i] <= s[i, k], i = 1 .. n), k = 1 .. m)}:

constraint7 := `union`(c3, c4):

 

For x[i, j, k] and s[i, k], we*require

 

Constraint (8): Setting the condition i ≠ j

                          OPEN

 

Constraint (9): Setting the condition i≠ n+1 

                          OPEN

 

Constraint (10): Setting the condition  j ≠ 0

                           OPEN

 

Constraint (11)

The final constraint ", x[i,j,k ] in  {0,1}, "require binary outputs, zero or one.

 

Excluding constraints (8) to (10), the consolidated constraints are:

constraints := `union`(`union`(`union`(`union`(`union`(`union`(constraint1, constraint2), constraint3), constraint4), constraint5), constraint6), constraint7):

 

 

The list, L, of all terms is given by the sequence:

L := `union`({seq(seq(seq(c[i, j]*x[i, j, k], j = 0 .. n), i = 0 .. n), k = 1 .. m)}, constraints):

 

The set of elements "x[i,j,k ] alone is constrained to "binary variables. The binaryvariables option may be given by the indets syntax.

The solution is:

Sol := LPSolve(z, constraints, binaryvariables = indets(L, specindex(integer, x)));

[2, [s[1, 1] = HFloat(1.0), s[2, 1] = HFloat(5.0), s[3, 1] = HFloat(10.0), s[4, 1] = HFloat(15.0), x[0, 0, 1] = 0, x[0, 1, 1] = 1, x[0, 2, 1] = 0, x[0, 3, 1] = 0, x[0, 4, 1] = 0, x[0, 5, 1] = 1, x[1, 0, 1] = 1, x[1, 1, 1] = 0, x[1, 2, 1] = 0, x[1, 3, 1] = 0, x[1, 4, 1] = 0, x[1, 5, 1] = 0, x[2, 0, 1] = 0, x[2, 1, 1] = 0, x[2, 2, 1] = 1, x[2, 3, 1] = 0, x[2, 4, 1] = 0, x[2, 5, 1] = 0, x[3, 0, 1] = 0, x[3, 1, 1] = 0, x[3, 2, 1] = 0, x[3, 3, 1] = 1, x[3, 4, 1] = 0, x[3, 5, 1] = 0, x[4, 0, 1] = 0, x[4, 1, 1] = 0, x[4, 2, 1] = 0, x[4, 3, 1] = 0, x[4, 4, 1] = 1, x[4, 5, 1] = 0]]

(1)

 

 

END

END

(2)

NULL


 

Download Constraint.mw

Many thanks for the effort and response - I appreciate it.

As you recommended, I have included the worksheet. The constraints are incomplete (missing the final three). If you could review the structure, I'd be interested in your comments / feedback.

Thanks again!

 

Thanks so much!

@vv 

4 5 6 7 Page 6 of 7