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 03-17-2020 12:07 PM
(854 views)

Hi.

I am trying to see if I can solve the center of gravity location problem using SAS. So I am looking for articles / literature to set my model.

As an overview, I have a bunch of nodes , each of them with its own demand (weight). I have latitudes and longitudes of them.

I am looking to find a center of gravity point that will minimize the "weighted-distance" from this center of gravity point to all nodes.

And as an extension, want to see if i can choose from a list of candidates that will minimize the weighted-distance.

Any help is appreciated

1 ACCEPTED SOLUTION

Accepted Solutions

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

21 REPLIES 21

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

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

Thanks Rob. I will look into it.

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

Rob

I did see that. It gave me a good insight. Thank you.

I was going to ask you for any example models in SAS related to this that I can learn so that I could better formulate it.

Thanks again

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

I happened to already have code for this:

```
proc optmodel;
set DIMS = 1..2;
set CUSTOMERS;
num a {CUSTOMERS, DIMS};
num demand {CUSTOMERS};
read data indata into CUSTOMERS=[_N_] {d in DIMS} <a[_N_,d]=col('a'||d)> demand;
var X {DIMS};
min Z = sum {i in CUSTOMERS} demand[i]*sqrt(sum {d in DIMS}(a[i,d]-X[d])^2);
solve;
print X;
create data sganno from [i]=CUSTOMERS x1=a[i,1] y1=a[i,2] x2=X[1] y2=X[2]
drawspace='datavalue' function='line';
quit;
proc sgplot data=cdata sganno=sganno;
scatter x=a1 y=a2;
run;
```

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

Rob that is really amazing.thank you

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

Rob.

I went into your model and also did some research to understand basic concepts about these types of problems.

Now I am ready to deploy SAS and test it on my small model. I have two columns called Sitename (that are nothing but customer names ) and Demand. I have 6 Sitenames and demand for each 6 of them. My objectives is to pick "n" points that will minimize the sum of the weighted distance to all the customers. Once this is set up correctly, I shall go on with choosing from a list of candidate facilities.

Sitename | SiteParameter1 |

DEN | 800 |

SFO | 150 |

EWR | 300 |

SEA | 200 |

MIA | 50 |

MCI | 500 |

ORD | 1000 |

I will have a set of customers (set CUSTOMERS;)

I will have a numeric parameter called demand that is indexed over CUSTOMERS (num demand {CUSTOMERS};)

The other numeric parameter that I see in your code num a{CUSTOMERS,DIMS} and your read data I am not quite sure I follow it. I am understanding that to be another parameter which will be like Customer1, Customer2 etc?

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

Can you help me how to read data / understand read data ? Also, model will give the optimum X,so that will be one of the 7 sites. Correct?

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

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

Thank you Rob for the insights. I am clear now. I will set up the model and let you know.

This is very interesting. Thank you again.

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

Rob

I wanted to let you know that I was able to adapt the code to my needs. and was able to get what I exactly wanted.

Thank you very much.

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

Glad to hear that, Santha!

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

I have a full model with 11,000 customers. Its been like 45 minutes and is still running.

I want model to pick 1 answer.

How do I set the tolerance / relative gap so that I can live with that % . Also, a time limit until the model can run like an hour or so and give the answers after 1 hr mark.?

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

Trying FEASTOL and MAXTIME based on NLP options. Any other ideas?

- 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 - here is the code.

%let p=2;

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;

print demand;

print a;

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} = sum{d in DIMS} GEODIST(a[i,1],a[i,2],X[j,1],X[j,2]);

min Z = sum {i in CUSTOMERS, j in FACILITIES} W[i,j]*Distance[i,j];

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

solve with nlp / ms FEASTOL=1e-1;

print X;

put _OBJ_=;

/* post-processing: assign each customer to closest facility */

set CUSTOMERS_j {FACILITIES} init {};

num minDistance, argminDistance;

for {i in CUSTOMERS} do;

minDistance = constant('BIG');

argminDistance = .;

for {j in FACILITIES} do;

if minDistance > Distance[i,j] then do;

minDistance = Distance[i,j];

argminDistance = j;

end;

end;

for {j in FACILITIES} W[i,j] = 0;

W[i,argminDistance] = demand[i];

CUSTOMERS_j[argminDistance] = CUSTOMERS_j[argminDistance] union {i};

end;

put _OBJ_=;

/* post-processing: solve each facility separately */

min SingleFacilityObjective {j in FACILITIES} = sum {i in CUSTOMERS_j[j]} demand[i]*Distance[i,j];

problem SingleFacilityProblem {j in FACILITIES} include

{d in DIMS} X[j,d]

SingleFacilityObjective[j];

for {j in FACILITIES} do;

put j=;

use problem SingleFacilityProblem[j];

solve;

end;

put (sum {j in FACILITIES} SingleFacilityObjective[j])=;

print X;

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.