Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 06-25-2020 04:31 PM
(815 views)

Hi Rob.

I am trying to use sparse modeling as suggested by you few months back. https://go.documentation.sas.com/?docsetId=ormpug&docsetTarget=ormpug_optmodel_examples07.htm&docset...

Here is my code. I want to pick p number of facilites that satisfy my customer demand. The following code is an adapted version of the code that you had earlier but the only thing is that I added the CUSTOMERS_SITES to cull out those customers_facilities pairs that has less than 1000 miles as the distance. When I ran the model, I got error that said " A set expression may not depend on a variable". That was my first question. Second question is if my objective function and constraints are right.

proc optmodel;

set DIMS=1..2;

set CUSTOMERS;

set FACILITIES = 1..&p;

num a {CUSTOMERS,DIMS};

num demand {CUSTOMERS};

read data STDOPT.COGMODELINGDATA into CUSTOMERS=

[_N_] {d in DIMS} <a[_N_,d]=col('a'||d)> demand;

num Xlb {d in DIMS} = min {i in CUSTOMERS} a[i,d];

num Xub {d in DIMS} = max {i in CUSTOMERS} a[i,d];

print Xlb; print Xub;

var X {FACILITIES, d in DIMS} >= Xlb[d] <= Xub[d];

var W {CUSTOMERS, FACILITIES} >= 0;

impvar Distance {i in CUSTOMERS, j in FACILITIES} = GEODIST(a[i,1],a[i,2],X[j,1],X[j,2]);

set CUSTOMERS_SITES = {i in CUSTOMERS, j in FACILITIES: Distance[i,j] <= 1000};

min Z = sum {<i,j>i in CUSTOMER_SITES} W[i,j]*Distance[i,j];

con DemandCon {i in CUSTOMERS}: sum {j in FACILITIES} W[i,j] = demand[i];

expand;

solve with nlp ;

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

10 REPLIES 10

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The ERROR message is because your set CUSTOMERS_SITES depends on Distance, which is an implicit variable. Sets must depend on constants and not variables.

It looks like you are mixing two related facility location problems. For both of them, the input includes a set of customers, each of whose demand must be satisfied by a fixed number (p) of facilities. The difference between the two problems is where the facilities can be built:

- If the facilities can be built anywhere, this is an NLP problem (the
*multisource Weber problem*). - If the facilities must be built at locations that are chosen from among a finite set of candidate sites, this is a MILP problem (the
*p-median problem*).

The sparse modeling approach applies only to the MILP problem. Which problem do you want to solve?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi Rob

Thank you very much. I am trying to solve multi source Weber problem. Can i then, just add a constraint saying someghing like

con radius {i in CUSTOMERS, j in FACILITIES} Distance [i,j]<=1000;?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Yes, that is legal if you include a colon:

`con radius {i in CUSTOMERS, j in FACILITIES}: Distance [i,j]<=1000;`

But I suspect that these additional nonlinear constraints will make the problem much harder to solve.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Rob. I tried that con radius even before i was experimenting sparse modeling without knowing that sparse modeling was for MILP.

The con radius constraint con radius {i in CUSTOMERS, j in FACILITIES}: Distance [i,j] <=1000;

does not give any error. But it also does not seems to respect the constraint because in the answer I do see some customer-Facility site pairs that have more than 1000 mile as distance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Rob - Solution Status is "Failed" as you can see in the below Solution Summary

Solution Summary SolverNLP

Algorithm Interior Point

Objective Function Z

Solution Status Failed

Objective Value 3796957.4976

Optimality Error 1394.3093905

Infeasibility702.52192689

Iterations 2245

Presolve Time 0.00

Solution Time 9.44

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

When i don't have that con radius, the solution status is "Iteration Limit Reached".

Solver NLP

Algorithm Interior Point

Objective Function Z

Solution Status Iteration Limit Reached

Objective Value 1675638.2436

Optimality Error 0.1991496343

Infeasibility 2.5283975E-7

Iterations 5000

Presolve Time 0.00

Solution Time 18.67

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Rob

Thank you very much for your feeback. Let me try to implement that and get back to you. Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Yes, Infeasibility > 0 implies that some constraints are violated.

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.