Having issues with the following problem: Problem description: A big-food compan
ID: 3885350 • Letter: H
Question
Having issues with the following problem: Problem description: A big-food company located in Norfolk, VA tries to run its main storehouse perfectly. The company receives new shipments every day at the storehouse. The company redistributes the shipment to a set of customers (small businesses) located in the Tidewater area (Norfolk, Chesapeake, Suffolk, Portsmouth, Va. Beach, and Hampton). The data at the storehouse are saved into records in three text files. The first line of each file shows the number of records in the file. A Record contains many fields, where fields are separated by a comma, as follow:
Shipments.txt: 1. Name of food item 2. Expiration Date (month:day:year) 3. Size of the Box (length:width:height) in inches 4. Weight of the box in pounds 5. Best Storage Method (refrigerate “R”, freeze “F”, do not refrigerate “D”) 6. Date Shipment Received (month:day:year) 7. Price of the Item (dollar.cent) Customers.txt: 1. Name of customer (small business) 2. Location (city name) of business 3. Distance from the Storehouse in miles Orders.txt: 1. Name of customer (small business) 2. Name of item needed 3. Number of boxes 4. Total cost (dollar.cent) 5. Date (month:day:year) order is placed
Task: Your task for this assignment is to write a C++ program to help the company run its warehouse. Use struct to represent the elements of the arrays. Name the arrays shipments, customers, orders. As a result, the data will be read into arrays of structs. The size of each array cannot be fixed; instead the size should be read from the corresponding data file except for shipments for which it is 20. All elements of an array are records read from a single file. The main() function of your program should be very simple. The main function should be a collection of variables declaration and functions call. You will need to use three different functions to read the data from the three files. You can add more functions if you want. You must provide the user with a capability of printing the data of any record (shipment, customer, and orders) on the computer monitor. You must also provide a function to search for a specific item in the shipments array. The search should be done by the item name and from the computer monitor. Do not use global variables except for the shipments struct array of size 20. Apart from this you can use at most one global variable. If you use more than the specified number of global variables there will be a deduction of 10 points from your total points.
Please check the attached “Grading Rubric” for the grading criteria. Sample Input/Output: The input files (Shipments.txt, Customers.txt and Orders.txt) are provided as attachments on the Blackboard under Assignment 1 > Instructions and supporting files. The following is the sample output. Your output may be exactly same as this one. This is just for reference. You can display in your own format but it should be easily understandable.
Input files:
Customers.txt
Orders.txt
Shipments.txt
250544421640120 114564311118232 555545435444555 115200525050309 222022222211222 000000010111000 RRDRDDDDRRDFRDD s-- t 050058656589445 222451627589655 292050500266666 116623266600320 --r--i | 006054957889892 --e--D_ 233412323243243 h= 111450509114164 114023294440430 020550505055665 115023215500220 555555565556555 kkenkhnkeknek ne y_ffspf e pf sfpsfps 055234615125522 322000002002200 102234504729222 010000010000011 sasps00 iy pnpnamtygawiaruExplanation / Answer
package com.graphhopper.jsprit.core.problem.job;
import java.util.Collection;
import com.graphhopper.jsprit.core.problem.AbstractJob;
import com.graphhopper.jsprit.core.problem.Capacity;
import com.graphhopper.jsprit.core.problem.Location;
import com.graphhopper.jsprit.core.problem.Skills;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindowsImpl;
public class Shipment extends AbstractJob {
public static class Builder {
private String id;
private double pickupServiceTime = 0.0;
private double deliveryServiceTime = 0.0;
private TimeWindow deliveryTimeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE);
private TimeWindow pickupTimeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE);
private Capacity.Builder capacityBuilder = Capacity.Builder.newInstance();
private Capacity capacity;
private Skills.Builder skillBuilder = Skills.Builder.newInstance();
private Skills skills;
private String name = "no-name";
private Location pickupLocation_;
private Location deliveryLocation_;
protected TimeWindowsImpl deliveryTimeWindows;
private boolean deliveryTimeWindowAdded = false;
private boolean pickupTimeWindowAdded = false;
private TimeWindowsImpl pickupTimeWindows;
private int priority = 2;
public Object userData;
public double maxTimeInVehicle = Double.MAX_VALUE;
/**
* Returns new instance of this builder.
*
* @param id the id of the shipment which must be a unique identifier among all jobs
* @return the builder
*/
public static Builder newInstance(String id) {
return new Builder(id);
}
Builder(String id) {
if (id == null) throw new IllegalArgumentException("id must not be null");
this.id = id;
pickupTimeWindows = new TimeWindowsImpl();
pickupTimeWindows.add(pickupTimeWindow);
deliveryTimeWindows = new TimeWindowsImpl();
deliveryTimeWindows.add(deliveryTimeWindow);
}
/**
* Sets user specific domain data associated with the object.
*
* <p>
* The user data is a black box for the framework, it only stores it,
* but never interacts with it in any way.
* </p>
*
* @param userData
* any object holding the domain specific user data
* associated with the object.
* @return builder
*/
public Builder setUserData(Object userData) {
this.userData = userData;
return this;
}
/**
* Sets pickup location.
*
* @param pickupLocation
* pickup location
* @return builder
*/
public Builder setPickupLocation(Location pickupLocation) {
this.pickupLocation_ = pickupLocation;
return this;
}
/**
* Sets pickupServiceTime.
* <p>
* <p>ServiceTime is intended to be the time the implied activity takes at the pickup-location.
*
* @param serviceTime the service time / duration the pickup of the associated shipment takes
* @return builder
* @throws IllegalArgumentException if servicTime < 0.0
*/
public Builder setPickupServiceTime(double serviceTime) {
if (serviceTime < 0.0) throw new IllegalArgumentException("serviceTime must not be < 0.0");
this.pickupServiceTime = serviceTime;
return this;
}
/**
* Sets the timeWindow for the pickup, i.e. the time-period in which a pickup operation is
* allowed to START.
* <p>
* <p>By default timeWindow is [0.0, Double.MAX_VALUE}
*
* @param timeWindow the time window within the pickup operation/activity can START
* @return builder
* @throws IllegalArgumentException if timeWindow is null
*/
public Builder setPickupTimeWindow(TimeWindow timeWindow) {
if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null");
this.pickupTimeWindow = timeWindow;
this.pickupTimeWindows = new TimeWindowsImpl();
this.pickupTimeWindows.add(timeWindow);
return this;
}
/**
* Sets delivery location.
*
* @param deliveryLocation delivery location
* @return builder
*/
public Builder setDeliveryLocation(Location deliveryLocation) {
this.deliveryLocation_ = deliveryLocation;
return this;
}
/**
* Sets the delivery service-time.
* <p>
* <p>ServiceTime is intended to be the time the implied activity takes at the delivery-location.
*
* @param deliveryServiceTime the service time / duration of shipment's delivery
* @return builder
* @throws IllegalArgumentException if serviceTime < 0.0
*/
public Builder setDeliveryServiceTime(double deliveryServiceTime) {
if (deliveryServiceTime < 0.0) throw new IllegalArgumentException("deliveryServiceTime must not be < 0.0");
this.deliveryServiceTime = deliveryServiceTime;
return this;
}
/**
* Sets the timeWindow for the delivery, i.e. the time-period in which a delivery operation is
* allowed to start.
* <p>
* <p>By default timeWindow is [0.0, Double.MAX_VALUE}
*
* @param timeWindow the time window within the associated delivery is allowed to START
* @return builder
* @throws IllegalArgumentException if timeWindow is null
*/
public Builder setDeliveryTimeWindow(TimeWindow timeWindow) {
if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null");
this.deliveryTimeWindow = timeWindow;
this.deliveryTimeWindows = new TimeWindowsImpl();
this.deliveryTimeWindows.add(timeWindow);
return this;
}
/**
* Adds capacity dimension.
*
* @param dimensionIndex the dimension index of the corresponding capacity value
* @param dimensionValue the capacity value
* @return builder
* @throws IllegalArgumentException if dimVal < 0
*/
public Builder addSizeDimension(int dimensionIndex, int dimensionValue) {
if (dimensionValue < 0) throw new IllegalArgumentException("capacity value cannot be negative");
capacityBuilder.addDimension(dimensionIndex, dimensionValue);
return this;
}
/**
* Builds the shipment.
*
* @return shipment
* @throws IllegalArgumentException if neither pickup-location nor pickup-coord is set or if neither delivery-location nor delivery-coord
* is set
*/
public Shipment build() {
if (pickupLocation_ == null) throw new IllegalArgumentException("pickup location is missing");
if (deliveryLocation_ == null) throw new IllegalArgumentException("delivery location is missing");
capacity = capacityBuilder.build();
skills = skillBuilder.build();
return new Shipment(this);
}
public Builder addRequiredSkill(String skill) {
skillBuilder.addSkill(skill);
return this;
}
public Builder setName(String name) {
this.name = name;
return this;
}
public Builder addDeliveryTimeWindow(TimeWindow timeWindow) {
if(timeWindow == null) throw new IllegalArgumentException("time-window arg must not be null");
if(!deliveryTimeWindowAdded){
deliveryTimeWindows = new TimeWindowsImpl();
deliveryTimeWindowAdded = true;
}
deliveryTimeWindows.add(timeWindow);
return this;
}
public Builder addDeliveryTimeWindow(double earliest, double latest) {
addDeliveryTimeWindow(TimeWindow.newInstance(earliest, latest));
return this;
}
public Builder addPickupTimeWindow(TimeWindow timeWindow) {
if(timeWindow == null) throw new IllegalArgumentException("time-window arg must not be null");
if(!pickupTimeWindowAdded){
pickupTimeWindows = new TimeWindowsImpl();
pickupTimeWindowAdded = true;
}
pickupTimeWindows.add(timeWindow);
return this;
}
public Builder addPickupTimeWindow(double earliest, double latest) {
return addPickupTimeWindow(TimeWindow.newInstance(earliest, latest));
}
/**
* Set priority to shipment. Only 1 (high) to 10 (low) are allowed.
* <p>
* Default is 2 = medium.
*
* @param priority
* @return builder
*/
public Builder setPriority(int priority) {
if (priority < 1 || priority > 10)
throw new IllegalArgumentException("incorrect priority. only 1 (very high) to 10 (very low) are allowed");
this.priority = priority;
return this;
}
/**
* Sets maximal time the job can be in vehicle.
*
* @param maxTimeInVehicle
* @return
*/
public Builder setMaxTimeInVehicle(double maxTimeInVehicle){
if(maxTimeInVehicle < 0) throw new IllegalArgumentException("maxTimeInVehicle should be positive");
this.maxTimeInVehicle = maxTimeInVehicle;
return this;
}
}
private final String id;
private final double pickupServiceTime;
private final double deliveryServiceTime;
private final TimeWindow deliveryTimeWindow;
private final TimeWindow pickupTimeWindow;
private final Capacity capacity;
private final Skills skills;
private final String name;
private final Location pickupLocation_;
private final Location deliveryLocation_;
private final TimeWindowsImpl deliveryTimeWindows;
private final TimeWindowsImpl pickupTimeWindows;
private final int priority;
private final double maxTimeInVehicle;
Shipment(Builder builder) {
setUserData(builder.userData);
this.id = builder.id;
this.pickupServiceTime = builder.pickupServiceTime;
this.pickupTimeWindow = builder.pickupTimeWindow;
this.deliveryServiceTime = builder.deliveryServiceTime;
this.deliveryTimeWindow = builder.deliveryTimeWindow;
this.capacity = builder.capacity;
this.skills = builder.skills;
this.name = builder.name;
this.pickupLocation_ = builder.pickupLocation_;
this.deliveryLocation_ = builder.deliveryLocation_;
this.deliveryTimeWindows = builder.deliveryTimeWindows;
this.pickupTimeWindows = builder.pickupTimeWindows;
this.priority = builder.priority;
this.maxTimeInVehicle = builder.maxTimeInVehicle;
}
@Override
public String getId() {
return id;
}
public Location getPickupLocation() {
return pickupLocation_;
}
/**
* Returns the pickup service-time.
* <p>
* <p>By default service-time is 0.0.
*
* @return service-time
*/
public double getPickupServiceTime() {
return pickupServiceTime;
}
public Location getDeliveryLocation() {
return deliveryLocation_;
}
/**
* Returns service-time of delivery.
*
* @return service-time of delivery
*/
public double getDeliveryServiceTime() {
return deliveryServiceTime;
}
/**
* Returns the time-window of delivery.
*
* @return time-window of delivery
*/
public TimeWindow getDeliveryTimeWindow() {
return deliveryTimeWindows.getTimeWindows().iterator().next();
}
public Collection<TimeWindow> getDeliveryTimeWindows() {
return deliveryTimeWindows.getTimeWindows();
}
/**
* Returns the time-window of pickup.
*
* @return time-window of pickup
*/
public TimeWindow getPickupTimeWindow() {
return pickupTimeWindows.getTimeWindows().iterator().next();
}
public Collection<TimeWindow> getPickupTimeWindows() {
return pickupTimeWindows.getTimeWindows();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
/**
* Two shipments are equal if they have the same id.
*
* @return true if shipments are equal (have the same id)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Shipment other = (Shipment) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
@Override
public Capacity getSize() {
return capacity;
}
@Override
public Skills getRequiredSkills() {
return skills;
}
@Override
public String getName() {
return name;
}
/**
* Get priority of shipment. Only 1 = high priority, 2 = medium and 3 = low are allowed.
* <p>
* Default is 2 = medium.
*
* @return priority
*/
@Override
public int getPriority() {
return priority;
}
@Override
public double getMaxTimeInVehicle() {
return maxTimeInVehicle;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.