To get an optimizing solution for VRP using Graphhopper/jsprit - graphhopper

While solving Vehicle Routing problem using Graphhopper/jsprit, For example , we get the solution as follows
Pickup1 - job1
Pickup2 - job2
Pickup3 - job3
Delivery1 - job1
Delivery2 - job2
Pickup4 - job4
So the problem i have with this solution is, It is going for Pickup of job4 eventhough - job3 is still in the Vehicle. My ultimate aim would be to go for pickup only when the vehicle is empty.Also If a vehicle isn't going to be delivered before another pickup then it shouldn't have been picked up in the first place(For ex: job 3 in above example).
So any suggestions to help with the possible Hard type constraint to satisfy the above conditions? Please suggest.I will update any further details if needed.

Related

ColumnHistory of a table field within a form

I am attempting to utilize an idea I have found within an Access template listed as "Asset Tracking." One of the forms, Asset Details, has a comment tab with two fields, New Comments (which is associated with a comments field in the sourced table), and Comments History, which features the following code in the Control Source:
=ColumnHistory([RecordSource],"Comments","[ID]=" & Nz([txtID],0))
The code allows one to enter information into the comment field that then updates the comment history with that comment once the form is saved and closed. This is based on the append only option being set to "Yes" under the Long Text format. The result would look something like this:
[Version: 12/18/2019 5:00:22 PM ] Jonathan's Law
[Version: 12/18/2019 5:14:13 PM ] Complete Last Interview
[Version: 12/20/2019 9:35:52 AM ] Hello Paul
[Version: 12/20/2019 10:00:31 AM ]
[Version: 12/20/2019 11:42:54 AM ] And then she got fired
[Version: 12/20/2019 11:44:07 AM ] And never rehired.
I have a database that I am initially developing for my agency for incident management (four tables: Investigations, Investigations - Target(s), Investigations - Victim(s), Investigations - Target/Victim Joiner. See this previous question for more details), and I saw that this code would be handy in identifying when an allegation changes (i.e., Neglect to Mistreatment) or to provide a comment box with comment history of my own within the forms developed. I attempted the code in my form and created a text box with the following code(s) in the Control Source:
=ColumnHistory("[Investigations - Target/Victim Joiner]","Offenses","[TargetID]=" & Nz([TargetID],0))
OR
=ColumnHistory([RecordSource],"Offenses","[TargetID]=" & Nz([TargetID],0))
Originally I tried to have either of these on the main form but I realized that the main form does not directly source the correct tables needed (I was getting a #Name? error and could not remedy it), but one of the subforms within the form did. I attempted the above codes in a text box within my allegationsubform and now receive a #Error code. I am really not sure how to proceed; I am looking for a way essentially to create an audit trail of changes to one's offenses (and eventually outcomes) as they are changed. I am wondering if the many to many relationship between victims and targets based on my arrangement is also creating issues (the TargetID and VictimID on the junction table are both PK's as part of the many to many); in which case, I am curious if something like the following code (it didn't work for me) would be on the right path:
=ColumnHistory([RecordSource],"Offenses","[TargetID]=" & Nz([TargetID],0) & "[VictimID]=" & Nz([VictimID],0))
Any help regarding this would be much appreciated; my entire Friday has gone into trying to identify an article that clearly explains where I am going wrong and none so far have helped me make the connection. All errors I have seen others correct are either the result of the code miraculously working without explanation of what was changed, or a minor grammatical error was present (i.e., missing quotes) in the code.
Sources of Research prior to asking question:
How do I display a memo field to a Form in Access
https://access-programmers.co.uk/forums/showthread.php?t=293527
https://answers.microsoft.com/en-us/msoffice/forum/all/creating-a-comments-history-box/56c1b861-f081-442c-aaa5-02b95eae14b9
https://learn.microsoft.com/en-us/office/vba/api/Access.Application.ColumnHistory
Need an " AND " in the criteria:
=ColumnHistory("YourTableName","Offenses","[TargetID]=" & Nz([TargetID],0) & " AND [VictimID]=" & Nz([VictimID],0))

How do I fetch data for a machine running log with different 'start' 'stop' entry in mysql?

My application keeps track of machines that are 'started' and 'stopped' as many times as needed, and this information is saved in the same table with the fields machine_ID, timestamp, entry_type(start/stop).
A start creates a row, and a stop creates a different row.
Sample start row : M1 - 2019-06-27 12:08:30 - 'start'
Sample stop row : M1 - 2019-06-27 14:30:05 - 'stop'
I need to be able to display:
1) All currently running machines (Machines that don't have a stop entry after the latest start entry)
2)A timeline of the previous machine activity preferably chronologically. Eg Machine 1 started: 09AM stopped 10 AM, Machine 2 started: 1pm, stopped 2pm, etc.
I imagine a result table as follows would be what I need but I can't understand how to build a query to fetch it.
'M1 - 2019-06-27 12:08:30 - 'start''
'M1 - 2019-06-27 14:30:05 - 'stop''
'M1 - 2019-06-27 16:00:00 - 'start''
'M1 - 2019-06-27 16:30:00 - 'stop''
'M2 - 2019-06-27 16:00:00 - 'start''
'M2 - 2019-06-27 16:30:00 - 'stop''
I plan tp use PHP to parse through such a table.
I am unable to alter the table structure in any way.
I believe the general principle behind solutions to this kind of problem has been well documented, however, not knowing how to refer to it, I am unable to do my own research.
Thanks.

select from table where two parameters satisfy in mysql

I am totally clueless how to get around to get the following kinda result from the same table in MySQL.
Required Result:
The raw data as shown in below image.
Mc_id and op_id can be different. For example, if mc_id is 4 and op_id is 10 then it has to loop through each vouid and extract done_on_date, again it has to loop through for the same mc_id 4 and op_id 10 and extract done_on_date where done_on_date is after first extracted done_on_date. Here second extracted done_on_date, we refer to, as next_done_on_date, just to distinguish it differently. Accordingly continue till end of the table. I hope I am clear enough now.
The idea is basically to see when was particular operation_id carried out for the said machine having mc_id. First time operation done is refered to as done_on_date and when the same operation carried out for the same machine next time, we refer to as next_done_on_date but actually inside the database table it is done_on_date.
Though let me know if anything yet to be clarified

SQL self-join to return specific rows

Skip to bottom to avoid long-winded explanation
Ok, so.
I'm working on a company intranet for managing client jobs. Jobs are comprised of Elements: an example element might be "Build a six-page website", or "Design a logo".
Each element consists of a collection of role-hours, so "Build a six-page website" might include four hours of "Developer" rate and two hours of "Designer" rate (ok, maybe a little longer :)
Obviously, different clients get different hourly rates. And, although that's already accounted for in the system, it's not giving us enough flexibilty. Traditionally, our account managers have been rather... ad hoc... with their pricing: the "Build a six-page website" element might include the standard four hours of developer for client "Bob", but eight hours for client "Harry".
Bear with me. I will get to actual code soon.
Elements are, of course, stored in the "Elements" database table - which is composed of little more than an ID and a text label.
My work-in-progress solution to the "we need client-specific elements" problem is to add a "client" field to this table. We can then go through and add any client-specific versions of the available elements, tweaking them to taste.
When the account managers go to add elements to their jobs, they should only see elements that are either (a) available to anyone - that is, they have a NULL client field, or (b) specific to the job client.
So far, so SELECT WHERE.
But that isn't going to cut it. If I add a second "Build a six-page website" element specifically for Harry, then an account manager adding elements to a job for Harry will see both the standard version, and Harry's version of the element. This is no good. They should only see the standard version if there's not an applicable client-specific version.
Ok... soooo: as well as adding a "client" field to the elements table, add a "parent element" field. We can then do something magically self-referential involving joining the table to itself, and fetch only the relevant roles.
My long-awaited question is thus:
Oh look, an actual question
id label client parent_element
1 Standard Thing NULL NULL
2 Harrys Thing 1 1
3 Bobs Thing 2 1
4 Different Thing NULL NULL
Given this table structure, how can I write a single SQL query that will accept a "client ID" parameter and return:
For client ID 1, rows 2 and 4
For client ID 2, rows 3 and 4
For client ID 42, rows 1 and 4
For extra bonus points, the results should include the parent element label. So for client ID 1, for example:
id label standardised_label client parent_element
2 Harrys Thing Standard Thing 1 1
4 Different Thing Different Thing NULL NULL
SELECT mm.*, md.label AS standardized_label
FROM mytable md
LEFT JOIN
mytable mc
ON mc.parent_element = md.id
AND mc.client = #client
JOIN mytable mm
ON mm.id = COALESCE(mc.id, md.id)
WHERE md.client IS NULL
Create an index on (client, parent_element) for this to work fast.
See SQLFiddle.

Translating complex logic to MySQL CASE statement

I'm having translating the following logic into a MySQL CASE statement, I'm sure there is an elegant way to do it but I think I have been working on for way too long and confused my self!
The business rules:
Programmes have an programme_start and programme_end
Individuals have an attend_start and attend_end
Individuals attend multiple programmes during one period, they can only have one of the following example attendance spans:
What I need to do is categorise each span into a category type i.e. Type 1 ... 9. but I'm having trouble building up a CASE statement that can mutually exclusively cover each span.
Has anyone done something like this before? If not could someone help with the logic behind it?
Thanks in advance!
The cases are quite simple..
In the case of a single time, there are only 3 ways a time can be classified - before, on and after. There are two times involved, so 3 x 3 = 9 results.
There is something to be said about consistency though, because for _start, it goes:
on - after - before
Whereas for the _end time, it goes
on - before - after
Combine them using (assuming no consideration for NULLs):
case when programme_start = attend_start then 0
when programme_start < attend_start then 3
else 6 end
+
case when programme_end = attend_end then 1
when programme_end > attend_end then 2
else 3 end
AS Category