2

RパッケージLPSolve、特にlp.transport関数を使用して最適化問題を解決しようとしました。以下の架空の例では、最小限の従業員数でリソースを確保する必要がある 5 つのオフィス サイトがあり、各従業員の自宅からオフィスまでの距離を決定するコスト マトリックスを設定しました。オフィスごとの従業員数を最小限に抑えながら、通勤距離の合計を最小限に抑えたいと考えています。

私はすべての従業員を平等に扱っていたので、最初はこれが機能していました(1)。しかし、各従業員の効率性を評価すると、問題が発生し始めました。たとえば、officeX には 2 人のエンジニアが必要であり、50% 効率の 4 人のエンジニアまたは 200% 効率の 1 人のエンジニアで構成されている可能性があります。ただし、これを行うと、見つかった解決策は従業員を複数のオフィスに分割します。必要なのは追加の制約であるため、従業員は 1 つのオフィスにしか配置できないようにします。とにかく、うまくいけば、これで十分な背景がここにあり、私の例は次のとおりです。

Employee <- c("Jim","John","Jonah","James","Jeremy","Jorge")
Office1 <- c(2.58321505105556, 5.13811249390279, 2.75943834864996, 
      6.73543614029559, 6.23080251653027, 9.00620341764497) 
Office2 <- c(24.1757667923894, 19.9990724784926, 24.3538456922105, 
      27.9532073293925, 26.3310994833106, 14.6856664813007) 
Office3 <- c(38.6957155251069, 37.9074293509861, 38.8271000719858, 
      40.3882569566947, 42.6658938732098, 34.2011184027657) 
Office4 <- c(28.8754359274453, 30.396841941228, 28.9595182970988, 
      29.2042274337124, 33.3933900645023, 28.6340025144932) 
Office5 <- c(49.8854888720157, 51.9164328512659, 49.948290261029, 
      49.4793138594302, 54.4908258333456, 50.1487397648236)

#create CostMatrix
costMat<-data.frame(Employee,Office1, Office2, Office3, Office4, Office5)

#efficiency is the worth of employees, eg if 1 they are working at 100% 
#so if for example I wanted 5 Employees
#working in a office then I could choose 5 at 100% or 10 working at 50% etc...
efficiency<-c(0.8416298, 0.8207991, 0.7129663, 1.1406839, 1.3868177, 1.1989748)

#Uncomment next line to see the working version based on headcount
#efficiency<-c(1,1,1,1,1,1)

#Minimum is the minimum number of Employees we want in each office
minimum<-c(1, 1, 2, 1, 1)

#solve problem
opSol <-lp.transport(cost.mat = as.matrix(costMat[,-1]),
                 direction = "min", 
                 col.signs = rep(">=",length(minimum)), 
                 col.rhs = minimum, 
                 row.signs = rep("==", length(efficiency)), 
                 row.rhs = efficiency,
                 integers=NULL)

#view solution
opSol$solution 

# My issue is one employee is being spread across multiple areas, 
#what I really want is a extra constraint that says that in a row there
# can only be 1 non 0 value.
4

1 に答える 1

1

これはもはや輸送の問題ではないと思います。ただし、MIP モデルとして解くことはできます。 ここに画像の説明を入力

于 2016-02-29T16:53:04.703 に答える