Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.

Prescriptive optimization, R Error: help!




I've been trying to replicate what is commonly known as a location-allocation optimization with Alteryx. The context is as follows: I have a list of houses affected by the earthquake in Mexico, specifically Chiapas. I also have a list of potential warehouses where help could be stored. Ideally, the optimization should, for those houses that are within 5km of any warehouse potential location, select those warehouse locations that minimize travel distance from the affected houses (effectively, only getting as many warehouses as needed to cover the population). You can find the workflow attached, however I keep falling into the same error from the R console which I can't investigate since the script is closed off now. Any help is deeply appreciated.


Optimization (47) Tool #3: ERROR: constraint mode for Input Anchor A may not be selected correctly!
Optimization (47) Tool #3: Error in UseMethod("as.constraint") :
Optimization (47) Tool #3: no applicable method for 'as.constraint' applied to an object of class "function"
Optimization (47) Tool #3: Calls: AlteryxSolve ... constructModel -> constructModel.matrix_mode -> OP -> as.constraint
Optimization (47) Tool #3: Execution halted
Optimization (47) Tool #3: The R.exe exit code (4294967295) indicated an error.
Designer x64 Finished running Attempt.yxmd in 3:58 minutes with 3 errors and 1 warning




I started to try to decode your optimization tool but then realized that all you actually just need to run the find nearest spatial tool.  


Not sure if I am missing the point here but please see the workflow attached (Version 11.5).






This will link each house affected to the nearest warehouse, it ensures that all warehouses are within a 5km range. 


Please let me know if this is not what you want.





Hi Nick,


Hmm that is a rather simplistic solution, thing is, it won't minimize the amount of warehouse locations, it will just assign each house to the nearest warehouse, leaving an un-optimized amount of warehouses. Since warehouse locations are not based on a strategy, rather they are selected from available public owned buildings, we want to minimize the amount to use, hence why I was using the optimization tool.


The whole idea is that the optimization tool should select those warehouses that may not be the nearest, but will be strategically positioned to cover all the houses under a distance constraint (which is why my workflow has a filter to only allow for warehouses within a certain distance), all the while minimizing the amount of warehouses needed to cover such houses.


Hi @Ehatie - since your variables are in rows, you'll use the constraint mode: Dense matrix, variables in rows. However, that does not return a solution, so perhaps take a closer look at your data and objective. 



 Hi @Ehatie,

The error you are getting is because an inconsistent constraint mode was selected. Based on the way your data is formatted, you need to select Dense matrix, variables in rows instead of Dense matrix, constraints in rows under the Select constraint mode for Input Anchor A set-up option. Changing this allows your model to run, however, you now will get the error TM_NO_SOLUTION. I think this is because you've set your warehouses as a constraint, where each warehouse needs to be <= 1. This is essentially saying that each warehouse can only be used once (can only service one home).  


For some reference on setting up your Optimization, I would refer to this post:


And the sample workflow in Alteryx:


Help> Sample Workflows> Prescriptive Analytics> 1_Optimization_Model_Input_Modes


Good luck!


 I can't believe the error was so simple haha


Either way, the reason even after fixing that, that makes it so I can't work it, is because R runs out of RAM memory to work on in my laptop. Basically I can't optimize the whole data set at once, but have to do iterative runs.


Cheers, and thanks for the solution.


Also true, which makes me question why in earlier versions it used to work somehow on a different kind of problem. Either way I switched the warehouse constrain to be >= 0 to see if that yields something close to what I wanted (I've already run this problem in other optimizers, but trying to learn how to do it in Alteryx now, so I have a good idea of the solution).