Group Abstract Group Abstract

Message Boards Message Boards

Deploy a custom function to the cloud

Posted 12 years ago

Hi there! I've just discovered the Wolfram Cloud service and I wanted to deploy a custom function to test the service but I've got some problems.

Here's what I'm trying:

optimize[d_, p_] := Module[{n, m, q, k, A, b, result},
    n=Length[d]; 
    m=Dimensions[p][[2]]; 
    vec[m_]:=Flatten[m[Transpose]]; 
    mat[v_]:=Partition[v,n][Transpose]; 
    j[k_]:=ConstantArray[1,k]; 
    q=j[m]; 
    k=vec[p (d[TensorProduct]q)]; 
    A=ArrayFlatten[{IdentityMatrix[m][TensorProduct]j[n]}]; 
    b=j[m][TensorProduct]{1,0}; 
    result = mat[LinearProgramming[k,A,b]]; 
    result 
]; 
CloudDeploy[APIFunction[{"d" -> "List", "p" -> "List"}, optimize[#d, #p] &, "String"]]

I'm using List as a parameter because d and p are like

d={7,5,11,3};
p=({{5,2,5,3,7,1,1,5,2,5,3,7,1,1},{2,8,3,2,7,2,3,2,8,3,2,7,2,3},{3,6,4,5,9,1,1,3,6,4,5,9,1,1},{4,6,2,8,14,8,4,4,6,2,8,14,8,4}});

Now, the function works fine in my local notebook and hitting evaluate actually makes the deploy.

The problem is that the API doesn't return what I expect.

While I expect a string that contains the result matrix, it outputs:

Transpose[LinearProgramming[LinearProgramming[Transpose[{{{5,2,5,3,7,1,1,5,2,5,3,7,1,1},{2,8,3,2,7,2,3,2,8,3,2,7,2,3},{3,6,4,5,9,1,1,3,6,4,5,9,1,1},{4,6,2,8,14,8,4,4,6,2,8,14,8,4}} {{7,5,11,3}} ? ConstantArray[1, {1}[[2]]]}]], LinearProgramming[ArrayFlatten[{IdentityMatrix[{1}[[2]]] ? {1}}]], LinearProgramming[ConstantArray[1, {1}[[2]]] ? {1, 0}]]]

and I don't understand why.

Do you know what the problem is?

POSTED BY: Stefano T
4 Replies
Posted 12 years ago
POSTED BY: Stefano T
POSTED BY: Chad Knutson
POSTED BY: David Reiss
Posted 12 years ago
POSTED BY: Stefano T
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard