## 40 Reputation

10 years, 37 days

## @Markiyan Hirnyk  please explain ho...

suppose 1th-level objective function is 3x1+2x2-4y1 and 2th level objective function is 2y1+3x2, and problem has only constraint : x1+x2-y1<=3

how can we solve it in maple?

## @Carl Love our ampl code is:restart...

our ampl code is:

restart:

randomize(2): #Needed to get nontrivial minimal paths.

N:= 100:  #Number of vertices

E:= 2300: #Number if directed edges

CartProdSeq:= proc(L::seq(list))

local Seq,i,j;

eval({subs(Seq=seq, foldl(Seq

, [cat(i,1..nargs)]

, seq(cat(i,j)=L[j],j=nargs..1,-1)

))});

end proc:

AllPossibleEdges:= [
(CartProdSeq([\$1..N], [\$1..N]) minus
{seq([k,k], k= 1..N)}
)[]
]:

Edges:= combinat:-randcomb(AllPossibleEdges, E):

Weights1:= RandomTools:-Generate(list(float(method= uniform), E)):

WeightedEdges1:= {zip(`[]`, Edges, Weights1)[]}:

G1:= GraphTheory:-Graph(WeightedEdges1);

Weights2:= RandomTools:-Generate(list(float(method= uniform), E)):

WeightedEdges2:= {zip(`[]`, Edges, Weights2)[]}:

G2:= GraphTheory:-Graph(WeightedEdges2);

(Path1,Cost1):= GraphTheory:-DijkstrasAlgorithm(G1, 1, N)[];

(Path2,Cost2):= GraphTheory:-DijkstrasAlgorithm(G2, 1, N)[];

Path_to_Edges:= proc(P::list)
local k;
{seq([P[k], P[k+1]], k= 1..nops(P)-1)}
end proc:

PPath1:= Path_to_Edges(Path1);

PPath2:= Path_to_Edges(Path2);

G3:= GraphTheory:-Graph(PPath1 union PPath2);

ApplyWeights:= proc(G1::GraphTheory:-Graph, G2::GraphTheory:-Graph)
#Apply the weights from G1 to G2.
uses GT= GraphTheory;
local W:= GT:-WeightMatrix(G1, copy= false);
GT:-Graph(
map(e-> [e, W[e[]]], GT:-Edges(G2, weights= false))
)
end proc:

G4:= ApplyWeights(G1, G3);

G5:= ApplyWeights(G2, G3);

..........................................

but ApplyWeights has no output.

in other words.ApplyWeights does not return G4 and G5

thanks

## @Carl Love according to:(Path1,Cost...

we have:

G1:= GraphTheory:-Graph(WeightedEdges1);

G2:= GraphTheory:-Graph(WeightedEdges2);

so G1 and G2 have the same edges but different weights.

moreover according to:

(Path1,Cost1):= GraphTheory:-DijkstrasAlgorithm(G1, 1, N)[];

(Path2,Cost2):= GraphTheory:-DijkstrasAlgorithm(G2, 1, N)[];

path1's edges set is a subset of G1's edges set and path2 edges set is a subset of G2's edges set. in G3, we want path1 edges and path2 edges have the weights that they have in G1. also in G4, path1 edges and path2 edges should have the weights that they have in G2.

G3 and G4 are defined as below:

G3:= GraphTheory:-Graph(PPath1 union PPath2);

G4:= GraphTheory:-Graph(PPath1 union PPath2);

so if [a,b] be coomon edge in path1 and path2, we have no problem. because [a,b] in G1 has a weight w1 and in G2 has a weight w2.

## Re...

i tried this code
it works.
but G3:= GraphTheory:-Graph(PPath1 union PPath2) isn't a weighted graph. since G3 is union of path1 and path2, we expect that weights of it's edges are weights of edges of ppath1 and ppath2.how can we do this?

## @Carl Love  @Carl Love  Dear C...

Dear Carl love

I sincerely thank you for your guidance

## @Carl Love  Dear Carl love I sincer...

Dear Carl love

I sincerely thank you for your guidance

http://www.mediafire.com/view/7b4pafbh4wd03aw/MyWorksheet-alpha041.mw

## Re...

Dear Carl love

Unfortunately GraphTheory:-Graph({Path1[], Path2[]}); does not work.

this error was shown:

Error, (in GraphTheory:-Graph) invalid argument

## re-type of question...

Hi

i have two questions about paths in graph package:

1. suppose we have:

path1=[1,3,5,7,9]

path2=[1,2,3,6,7,8,9]

if we want to create a graph that it's edges are edges of path1 and edges of path2,how can we do this?

edge set of our graph should be {[1,3],[3,5],[5,7],[7,9],[1,2],[2,3],[3,6],[6,7],[7,8],[8,9]}

2. suppose p is an arbitrary path on a given weighted graph G

how can i calculate weight of p (that is sum of it's edges weights) in maple ?

thanks very much for your help

## new question...

thanks dear Carl love

in your code,i want to create a subgraph of G that contains only edges on path 1 and path 2 (path 1 is minimal cost path with weights w1 and path 2 is minimal cost path with weights w2),how can i do this?

i trid GG := GraphTheory-Graph(Path1 union  Path2) but error was shown.

 Page 1 of 1
﻿