Cost Vector Formulation-Shipment Cost Minimization

Hi All,

I am trying to solve shipment cost minimization. I am facing problem for creating Cost vector. Need your help to create Cost vector from a CSV file. Problem is as below

of suppliers 100 (let us denote them as “i”)

of plants 250 (let us denote then as “j”)

I need to make cost vector Cij for unit cost of shipment from “i” supplier to “j” plant.

The data is given in a row form in a CSV file. For your reference I am including the sample file.

Much Thanks.
VG

Something like this, maybe?

using CSVFiles, DataFrames

df = DataFrame(load("input.csv"))
nsups = length(unique(df[1:end, :Supplier]))
nplants = length(unique(df[1:end, :Plants]))

costmatrix = permutedims(reshape(df[1:end,:Cost], nplants, nsups), (2,1))

Note that I renamed the header of your data’s third column to just “Cost”.

It looks like it will bug out though if not all suppliers have all plants

That’s correct. In the general case, you could initialize the cost matrix with zeros and fill it with a loop.

Zeros may also be a bit of a hassle amongst cost values, as you’d probably want to find minimums and you might miss the freebies

costmat = Array{Union{Float64, Symbol}}(undef, nplants, nsups); costmat .= :Soldout

and maybe

function lookup_tab(dcol)
  xkeys = unique(dcol); ##df[1:end, :Supplier]
  xtab = Dict();
  [xtab[xkey] = xval for (xval, xkey) in enumerate(xkeys)];
  return xtab;
  end;

Thanks a lot. It worked.

But I couldn’t understand if not all suppliers have plants then how to resolve that bug? (I am a beginner at this so has very limited exposure to Julia as well as programming)