Question

Question 3 - Dynamic Programming 18 marks total a) Consider an acyclic network defined by a set of nodes N and a set of arcs

this is a dynamic programming problem

0 0
Add a comment Improve this question Transcribed image text
Answer #1


#include <bits/stdc++.h>
#include<iostream>
using namespace std;

// a structure to represent a weighted edge in graph
struct Edges
{
int src, dest, weight;
};

//weighted graph
struct Data
{
//these two represents vertex and edges
int V, E;


struct Edges* edge;
};

struct Data* createGraph(int V, int E)
{
struct Data* graph = new Data;
graph->V = V;
graph->E = E;
graph->edge = new Edges[E];
return graph;
}

void printArr(int dist[], int n)
{
printf("Vertex Distance from Source\n");
for (int i = 0; i < n; ++i)
printf("%d \t\t %d\n", i, dist[i]);
}
//Asyclic graph
void BellmanFord(struct Data* graph, int src)
{
int V = graph->V;
int E = graph->E;
int dist[V];


for (int i = 0; i < V; i++)
dist[i] = INT_MAX;
dist[src] = 0;

for (int i = 1; i <= V-1; i++)
{
for (int j = 0; j < E; j++)
{
int u = graph->edge[j].src;
int v = graph->edge[j].dest;
int weight = graph->edge[j].weight;
if (dist[u] != INT_MAX && dist[u] + weight < dist[v])
dist[v] = dist[u] + weight;
}
}
for (int i = 0; i < E; i++)
{
int u = graph->edge[i].src;
int v = graph->edge[i].dest;
int weight = graph->edge[i].weight;
if (dist[u] != INT_MAX && dist[u] + weight < dist[v])
printf("Graph contains negative weight cycle");
}

printArr(dist, V);

return;
}


int main()
{

int V=5;//you can change the input as you want
int E=8;

struct Data* graph = createGraph(V, E);

// add edge 0-1 (or A-B in above figure)
graph->edge[0].src = 0;
graph->edge[0].dest = 1;
graph->edge[0].weight = -1;

// add edge 0-2 (or A-C in above figure)
graph->edge[1].src = 0;
graph->edge[1].dest = 2;
graph->edge[1].weight = 4;

// add edge 1-2 (or B-C in above figure)
graph->edge[2].src = 1;
graph->edge[2].dest = 2;
graph->edge[2].weight = 3;

// add edge 1-3 (or B-D in above figure)
graph->edge[3].src = 1;
graph->edge[3].dest = 3;
graph->edge[3].weight = 2;

// add edge 1-4 (or A-E in above figure)
graph->edge[4].src = 1;
graph->edge[4].dest = 4;
graph->edge[4].weight = 2;

// add edge 3-2 (or D-C in above figure)
graph->edge[5].src = 3;
graph->edge[5].dest = 2;
graph->edge[5].weight = 5;

// add edge 3-1 (or D-B in above figure)
graph->edge[6].src = 3;
graph->edge[6].dest = 1;
graph->edge[6].weight = 1;

// add edge 4-3 (or E-D in above figure)
graph->edge[7].src = 4;
graph->edge[7].dest = 3;
graph->edge[7].weight = -3;
//you can use the loop to manipulate more data example purpose only these are given
BellmanFord(graph, 0);

return 0;
}

CAUsers\senthilmurugan\Documents12.exe Vertex le 1 Distance from Source 0 2 4 Process returned 0 (0x0) Press any key to conti

B)

#include<iostream>

using namespace std;

int good()

{

static int n=0;

int total;

total=300+(0.95*0.8*n);

n++;

return total;

}

int bad()

{

static int n=0;

int total;

total=700+(0.9*0.1*n);

return total;

}

int main()

{

int years,goodMaintain,badMaintain;

cout<<"enter the number of years"<<endl;

cin>>years;

for(int i=0;i<3;i++)

{

goodMaintain= good();

badMaintain=bad();

}

cout<<"for good "<<goodMaintain;

cout<<"for bad:"<<badMaintain;

return 0;

}

Add a comment
Know the answer?
Add Answer to:
this is a dynamic programming problem Question 3 - Dynamic Programming 18 marks total a) Consider an acyclic network de...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem 1: Dynamic Programming in DAG Let G(V,E), |V| = n, be a directed acyclic graph...

    Problem 1: Dynamic Programming in DAG Let G(V,E), |V| = n, be a directed acyclic graph presented in adjacency list representation, where the vertices are labelled with numbers in the set {1, . . . , n}, and where (i, j) is and edge inplies i < j. Suppose also that each vertex has a positive value vi, 1 ≤ i ≤ n. Define the value of a path as the sum of the values of the vertices belonging to...

  • Question 3 10 marks total a) Suppose stamps can be bought in denominations of $0.10, $0.70 and $1.20. Design a dynamic...

    Question 3 10 marks total a) Suppose stamps can be bought in denominations of $0.10, $0.70 and $1.20. Design a dynamic programming formulation that willl find the minimum number of stamps necessary for a postage value of $x (in any multiple of $0.10). Show how your formulation works to calculate the minimum number of stamps necessary for a postage value of $1.40. [5 marks] b) Suppose Michelle currently has $2 and is allowed to play a game of chance three...

  • hi i need answer from part d Question 2 (48 marks) Consider a firm which produces a good, y, using two factors of...

    hi i need answer from part d Question 2 (48 marks) Consider a firm which produces a good, y, using two factors of production, xi and x2 The firm's production function is Note that (4) is a special case of the production function in Question 1, in which α-1/2 and β-14. Consequently, any properties that the production function in Q1 has been shown to possess, must also be possessed by the production function defined in (4). The firm faces exogenously...

  • Please read the case provided below and answer the following question: In 2007, JetBlue was a...

    Please read the case provided below and answer the following question: In 2007, JetBlue was a booming young airline with a strong reputation for outstanding service. In fact, the low-fare airline referred to itself as a customer service company that just happened to fly planes. But on Valentine's Day 2007, JetBlue was hit by the perfect storm-literally-of events that led to an operational meltdown. One of the most severe storms of the decade covered JetBlue's main hub at New York's...

  • The Mayo clinic is one of the most respected names in medicine world. Founded in the...

    The Mayo clinic is one of the most respected names in medicine world. Founded in the 1880s in Rochester, Minnesota, the Mayo clinic embraced innovation from the beginning. It is believed to be America’s first integrated group practice as it employed the concept of coordinated, specialized care and sought out the best expertise. At the core of the Mayo culture, from its inception to today, is a team approach and physician decision making rooted in shared responsibility and consensus building....

  • Read the attached article. Do you feel one style of banking control is more stable than...

    Read the attached article. Do you feel one style of banking control is more stable than the other? Why? Does one banking method minimize market volatility and risk better or is it just packaged differently? Do you feel the US (Western) Banking system can better control the patterns of behavior going forward that have caused economic damage in the past? Should the Fed continue its stimulus policy, reduce it or abandon it entirely (Google some recent articles to research this)?  (Please...

  • SYNOPSIS The product manager for coffee development at Kraft Canada must decide whether to introduce the...

    SYNOPSIS The product manager for coffee development at Kraft Canada must decide whether to introduce the company's new line of single-serve coffee pods or to await results from the product's launch in the United States. Key strategic decisions include choosing the target market to focus on and determining the value proposition to emphasize. Important questions are also raised in regard to how the new product should be branded, the flavors to offer, whether Kraft should use traditional distribution channels or...

  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

  • What should Ajanta do about its recent order from SF? AJANTA PACKAGING: KEY ACCOUNT MANAGEMENT Sandeep Puri and Rakesh Singh wrote this case solely to provide material for class discussion...

    What should Ajanta do about its recent order from SF? AJANTA PACKAGING: KEY ACCOUNT MANAGEMENT Sandeep Puri and Rakesh Singh wrote this case solely to provide material for class discussion. The authors do not intend to iustrate either effective or ineffective handling of a managerial situation. The authors may have disguised certain names and other identifying information to protect confidentiality This publication may not be transmitted, photocopied, digitized, or otherwise reproduced in any form or by any means without the...

  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT