Simple hamilton cycle reduction


HAMPATH

  • Input: A undirected graph G and 2 nodes s, t

  • Question: Does G contain a hamilton path from s to t?

HAMCYCLE

  • Input: A undirected graph G and a nodes s

  • Question: Does G contain a hamilton cycle starting at s?

I wish to show HAMCYCLE is NP-hard

I’ll show this by doing $ HAMPATH \leq_p HAMCYCLE$ since HAMPATH is known to be NP-COMPLETE

Reduction is as follows

$ (G, s, t) \to (G’, s’)$

where $ s’ = s$ and for $ G’$ I will add one edge from $ t$ to $ s’$

This is polynomial time because we are adding only an edge

if $ (G, s, t) \in HAMPATH$ , then we know there is a hamilton path from s to t, our graph G’ will be $ (s’, \dots, t)$ but since we added a edge from $ t$ to $ s’$ then

$ (s’, \dots, t, s’)$ , a cycle, thus $ (G’,s’) \in HAMCYCLE$

Now doing the converse, if $ (G’, s’) \in HAMCYCLE$ then there exist a hamilton cycle from $ (s’, …, s’)$ that visits every node and comes back to s’ meaning there is a node $ t$ right before $ s$ to make this a hamilton path, thus $ (G, s, t) \in HAMPATH$


Above is my entire attempt. I was wondering if I could call on $ t$ in my reduction since its not used as a input in HAMCYCLE ?

Determine if a graph has exactly 1 cycle using a SAT solver

I have a connected undirected graph whose edges are either enabled or disabled. I want to create a set of clauses that are SAT iff all enabled edges are part of a single loop.

If I assert that each vertex has either 0 or 2 enabled edges, then graphs where all enabled edges are part of a single loop will satisfy the clauses. However, graphs with multiple disjoint loops can will also satisfy those clauses. How can I make sure that only 1 loop graphs satisfy the clauses?

Is there a way to cycle through levels of a filter and generate outputs in R?

I am trying to generate report card outputs using R, but have over 200 agents (levels in my factor) that require their own report (tibble output that I can write to .csv or html).

I have included a reproducible example below.

library(tidyverse) Agents <- c("A", "B", "C") Month <- c("May", "June", "July") Score1 <- c(5,7,1) Score2 <- c(7,8,3)  df <- cbind(Agents, Month, Score1, Score2) df2 <- as.data.frame(df)  df2$  Score1 <- as.numeric(as.character(df2$  Score1)) df2$  Score2 <- as.numeric(as.character(df2$  Score2))  Report <- df2 %>%             group_by(Month) %>%            summarise(Skill = mean(Score1), Attitude = mean(Score2)) 

I would like to loop through my agents, using each as a filter on the Report, and then save it as Report_agentname. I took a look at purr but can’t quite get my head around the map function and my needs here.

Vicious cycle: No DPKG & No space left on device

Ubuntu 18.04.02 LTS on GCP

df -i Filesystem      Inodes  IUsed   IFree IUse% Mounted on /dev/root      3870720 158973 3711747    5% / devtmpfs       1923380    387 1922993    1% /dev tmpfs          1924177      1 1924176    1% /dev/shm tmpfs          1924177    554 1923623    1% /run tmpfs          1924177      8 1924169    1% /run/lock tmpfs          1924177     18 1924159    1% /sys/fs/cgroup /dev/loop0       12823  12823       0  100% /snap/core/7270 /dev/loop1       23213  23213       0  100% /snap/google-cloud-sdk/86 /dev/loop2       12820  12820       0  100% /snap/core/6964 /dev/sda15           0      0       0     - /boot/efi /dev/loop3       23074  23074       0  100% /snap/google-cloud-sdk/88 tmpfs          1924177     10 1924167    1% /run/user/1001 

Trying to do anything with the boot partition, such as

ls -l >>>... >>>cannot copy extracted data for './usr/lib/file/magic.mgc' to '/usr/lib/file/magic.mgc. dpkg-new': failed to write (No space left on device) 

Broken partition

sudo apt-get remove  linux-headers-4.15.0-1036-gcp    >>>E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct th e problem.  

Same when trying

sudo apt remove p7zip-full 

No space to fix the broken partition !

sudo dpkg --configure >>>dpkg: error: failed to write status database record about 'libstdc++6:amd64' to '/var/l ib/dpkg/status': No space left on device$   

Personagem volta pra trás no walk cycle unity 3d

Olá, a minha dúvida é a seguinte:

Sou iniciante na Unity3d e estou com um problema nas animações, o personagem caminha, e volta pra trás, e assim repetidamente. Segue a imagem do animation controller: Meu animation ontroller

Meu script C#:

using UnityEngine; public class playerMove : MonoBehaviour {     private Animator anim;     public float speed = 2.0f;     void Start()     {        anim = GetComponent<Animator>();     }     void Update()     {        if (Input.GetKey(KeyCode.W))         {             transform.Translate(Vector3.forward * Time.deltaTime);             anim.SetBool("isWalking", true);             anim.SetBool("idle", false);         }         else if (Input.GetKey(KeyCode.S)) {         transform.Translate(Vector3.back * Time.deltaTime);         anim.SetBool("isWalking", true);         anim.SetBool("idle", false);     }     else {         anim.SetBool("isWalking", false);         anim.SetBool("idle", true);     } } } 

Complexity of “half cycle”

I’m working on the following problem:

HALFCYCLE (HALFC):

Input:

A directed graph $ G = (V,E)$ .

Output:

Whether the longest cycle in $ G$ has length $ \lfloor |V|/2 \rfloor$ .

Prove that if $ \mathsf{PH} \ne \mathsf{coNP}$ then HALFCYCLE is not NP-complete.

I have no idea how to solve this implication.

Cycle through filenames in vim

So I have a list of files which names are something like this

long_boring_filename_del_1.tex long_boring_filename_del_2.tex long_boring_filename_del_3.sty long_boring_filename_del_4.tex 

I want to cycle through these filenames using some mapping defined in vim. Meaning if I have long_boring_filename_del_2.tex open and hit the mapping it should take me to the next file long_boring_filename_del_3.sty. It should also loop, meaning long_boring_filename_del_4.tex should take me back to long_boring_filename_del_4.tex.

In addition I want to be able to cycle thorugh the files in both directions.

After obtaining a bit of help over at vi and vim I was able to come up with the following solution (which works).

function! s:next_del()      " do nothing if current filename doesn't match "     if @% !~# 'del-\v[1234]\.'         return     endif      " open next file "     let fnameA = substitute(@%, '\v[1234]\ze\.', '\=submatch(0)%4+1', '')     if filereadable(fnameA)         exec 'echo'         exec 'e ' . fnameA     else          " if the .tex file does not exist check if the .sty versions does "         let fnameB = substitute(fnameA, '\.tex', '\.sty', '')         if filereadable(fnameB)             exec 'e ' . fnameB         else              " if the above fails, check if changing sty to tex works "             let fnameB = substitute(fnameA, '\.sty', '\.tex', '')             if filereadable(fnameB)                 exec 'e ' . fnameB             endif         endif     endif endfunction  " Same as s:next_del() except this cycles in the opposite direction " function! s:prev_del()      " do nothing if current filename doesn't match "     if @% !~# 'del-\v[1234]\.'         return     endif      " open previous file "     let fnameA = substitute(@%, '\v[1234]\ze\.', '\=submatch(0)-1', '')     let fnameA = substitute(fnameA, '\v[0]\ze\.', '\=submatch(0)+4', '')     if filereadable(fnameA)         exec 'e ' . fnameA     else          " if the .tex file does not exist check if the .sty versions does "         let fnameB = substitute(fnameA, '\.tex', '\.sty', '')         if filereadable(fnameB)             exec 'e ' . fnameB         else             " if the above fails, check if changing sty to tex works "             let fnameB = substitute(fnameA, '\.sty', '\.tex', '')             if filereadable(fnameB)                 exec 'e ' . fnameB             endif         endif     endif endfunction  nnoremap <silent> <localleader>w :call <sid>next_del()<CR> nnoremap <silent> <localleader>q :call <sid>prev_del()<CR> 

While it work I would love to get some pointers on how to improve the code as I am very much a beginner when it come to vimscript. Here are the major points in the code that needs improvement:

  • Can the two functions s:next_del() and s:prev_del() be combined into one?
  • My method of cycling backwards is very barbaric.

    let fnameA = substitute(@%, '\v[1234]\ze\.', '\=submatch(0)-1', '') let fnameA = substitute(fnameA, '\v[0]\ze\.', '\=submatch(0)+4', '') 

    I did it in this fashion because apparently you can’t separate the leading \ and = , as otherwise it’s a pure string. I would like to get some pointers on how to improve it.

  • Lastly my method of “checking” whether I have a sty file or tex file is strange at best. I do not really check, just change sty to tex and see if it works. I tried to get some regex going by using (tex|sty) but for some reason vimscript did not accept it. I would like to learn a better method of alternating between the sty and tex files.

Is a Minimum-Spanning-Tree always give a lower bound for the weight of any Hamiltonian cycle of the graph?

A minnimum-spanning-tree (MST) path is always V-1 number of edges and Hamiltonian Cycle (HC) always V number of edges. Because the HC has an extra edge we could say that in general, the weight of every Hamiltonian cycle of a connected graph will be less.

If we take an edge of every Hamiltonian cycle we will find an MST and by that, the MST weight will be always lower than HC.

  • There is a way to prove this where MST tree not necessary belongs to the HC?
  • There is more definitive proof for this?

Using Command + ` to cycle through windows across different Spaces in macOS Mojave

I use Command + Tab and Command + ` often when switching between apps/windows.

I also have multiple Spaces that I typically use. I’ve found that using Command + ` only cycles through windows in the current Space. Is there a way to have it cycle through all windows in an application, not just the one in the current space?

I found that Command + Option + (n) (where (n) is an integer) switches to a specific window of an application and handles windows across spaces fine, but I don’t really want to have to remember which window is which number when switching around.