Unclear error

Below, is example 6.2 from the book (Julia Programming for OR)
‘’’ import Pkg
Pkg.add(“DataFrames”)
Pkg.add(“CSV”)
Pkg.add(“JuMP”)
Pkg.add(“MathOptInterface”)
Pkg.add(“GLPK”)
Pkg.add(“Clp”)
Pkg.activate(@DIR)
Pkg.instantiate()
Pkg.add(“JuMP”)
Pkg.add(“DataStructures”)
Pkg.add(“OrderedCollections”)
using JuMP
using MathOptInterface # Replaces MathProgBase
using DataFrames, CSV

shortcuts

const MOI = MathOptInterface
const MOIU = MathOptInterface.Utilities
using Clp
using GLPK # Loading the GLPK module for using its solver
using DelimitedFiles
using OrderedCollections
using DataStructures

data=DataFrame!(CSV.File(“julija1.csv”, header=false))

supply_nodes=data[3:end,2]
demand_nodes=data[2, 3:end]
demand_nodes=collect(data[2,3:end]) #umesto 1x3 niza dobijamo 1x1 niz
s = data[3:end, 1]
d=data[1,3:end]
d=collect(data[1,3:end])
c=data[3:end, 3:end] #transportation const
#converting to Dictionaries
s_dict=OrderedDict()
for i in 1:length(supply_nodes)
s_dict[supply_nodes[i]]=s[i]
end
s_dict=OrderedDict(zip(supply_nodes,s)) #to keep the orders
d_dict=OrderedDict()
for i in 1:length(demand_nodes)
d_dict[demand_nodes[i]]=d[i]
end
d_dict=OrderedDict(zip(demand_nodes,d)) #to keep the orders
c_dict=OrderedDict()
for i in 1:length(supply_nodes)
for j in 1:length(demand_nodes)
c_dict[supply_nodes[i], demand_nodes[j]]=c[i,j]
end
end
tp = Model(GLPK.Optimizer)
@variable(tp, x[supply_nodes, demand_nodes]>=0)
@objective(tp, Min, sum(c_dict[i,j]*x[i,j] for i in supply_nodes, j in demand_nodes))’’’

Inputs:
15 12 13
Chicago Denver Erie
15 Austin 10 7 9
25 Buffalo 4 9 8

Everything was ok (and according to the book) until the @objective line, then this message has appeared:
ERROR: LoadError: MethodError: no method matching *(::String, ::VariableRef)
Closest candidates are:
*(::Any, ::Any, ::Any, ::Any…) at operators.jl:529
*(::MutableArithmetics.Zero, ::Any) at C:\Users\mmill.julia\packages\MutableArithmetics\NuiNA\src\rewrite.jl:49
*(::SparseArrays.SparseMatrixCSC, ::MutableArithmetics.AbstractMutable) at C:\Users\mmill.julia\packages\MutableArithmetics\NuiNA\src\dispatch.jl:181
Do you have any idea, what this occured?
Best,
marco

Somewhere in your code you are multiplying a string by a variable from JuMP. The full error message also contains a stacktrace which you can look through the determine which line is the culprit (I’m fairly sure it’s because of what’s in data, but you’ll have to look into that yourself)

When you paste code in discourse, you should do so in “triple bacticks”. I.e.
```
your code
```
comes out looking like:

your code

which makes it much easier to read. It looks like you tried to do that with quotes, but the correct symbol is the “backtick” which (on an american keyboard at least) is to the left of the number keys (the same key as ~).

2 Likes

Thank you. The problem was with csv file.

1 Like