# Install the "igraph" library unless it is already set up.
install.packages("igraph")
# Use the library.
library(igraph)
# Define the coefficients of the objective function as a matrix.
X = read.table(text = '2 3 5 6
2 1 3 5
3 8 4 6', header=FALSE)
# Size of the problem.
m = nrow(X)
n = ncol(X)
colnames(X) = paste("D", 1:n, sep="")
rownames(X) = paste("S", 1:m, sep="")
X
# Set a graph (network model), consisting of nodes and edges.
# The X matrix is part of the above solution.
# Nodes:
nodes = c(rownames(X),colnames(X))
# Since each of the S nodes is to be connected with each of the D nodes, the from and to nodes # can be generated as follows.
# Create a vector of the source nodes.
from = c('S1','S1','S1','S1','S2','S2','S2','S2','S3','S3','S3','S3')
# Create a vector of the destinations nodes.
to = c('D1','D2','D3','D4','D1','D2','D3','D4','D1','D2','D3','D4')
# Notice that pairs of from and to elements define the edges of the graph.
edges = data.frame(from, to)
# Create the graph.
transp_net = graph_from_data_frame(d = edges, vertices = nodes, directed = TRUE)
# Display the graph.
plot(transp_net)